archive-com.com » COM » S » SOLARPHP.COM

Total: 875

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Solar Framework for PHP 5
    through a relationship In general you won t need that method yourself 3 6 2 Modifying A Record Whether it is a new record or an existing one you can modify the properties of the record by addressing its properties individually or by using the load method to load an array of data to the record in one pass php var Solar Sql Model Record item The result of fetchNew or fetchOne or a record from a collection modify the properties individually item title Another Title item body Different body text or modify them via load data array status draft title Another Title body Different body text item load data only load certain properties useful for loading only specific values from a data source e g POST whitelist array title body item load data whitelist 3 6 3 Saving A Record Once you have modified the record you can call the save method to insert or update it to the database The record object knows if it is new it needs to be inserted otherwise it will update itself using its primary key value Note The record will save only the data that has changed that is only the dirty elements Because the model has defined certain filters for the record the save call will fail if any of the validations fail so you need to check if the save succeeded to see what went wrong php var Solar Sql Model Record item The result of fetchNew or fetchOne or a record from a collection and thereafter modified attempt to save the record success item save did it work if success no something was not valid invalid item getInvalid foreach invalid as property message echo htmlspecialchars property is not valid htmlspecialchars message br or you can get the internal exception

    Original URL path: http://solarphp.com/manual/model.record (2016-02-13)
    Open archived version from archive


  • Solar Framework for PHP 5
    depending on your needs 3 7 1 Automatic Filters These filters are added to these column types automatically Table 3 1 Filters Added Automatically In Models Column Info Filters Added boolean validateBool and sanitizeBool char and varchar validateString validateMaxLength for the defined column width and sanitizeString smallint int and bigint validateInt validateRange for the lowest and highest allowed values of each integer type and sanitizeInt numeric fixed point decimal validateNumeric validateSizeScope for the defines column size and scope and sanitizeNumeric float double validateFloat and sanitizeFloat clob none date validateIsoDate and sanitizeIsoDate time validateIsoTime and sanitizeIsoTime timestamp datetime validateIsoTimestamp and sanitizeIsoTimestamp What about NOT NULL columns Because of the way Solar Filter works a particular piece of data is not defined as required until filtering actually occurs This is because if a piece of data is missing it won t be filtered because there s nothing to filter As such NOT NULL columns are checked if they are present and not blank but this is done programmatically as part of the filtering logic not as a separate filter You can still add validateNotBlank on your own to make sure properties when present are filled in 3 7 2 Adding Filters To add one or more filters to a model edit the model setup method and call this addFilter with the record property name the filter name and the parameters if any for the filter php class Vendor Model Foo extends Vendor Sql Model public function setup validate that a username is only alphanumeric characters this addFilter user handle validateAlnum validate column user email is not blank and is an email address this addFilter user email validateNotBlank this addFilter user email validateEmail validate column foo is at least 8 characters long and has at least one non alphanumeric character this addFilter foo

    Original URL path: http://solarphp.com/manual/model.filters (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    Vendor Model Foo extends Vendor Sql Model public function setup use a column called first added as the created timestamp column this created col first added 3 8 2 Updated Timestamp The updated col property notes a table column to be automatically populated with the timestamp when the row is updated at the database By default the column is called updated but you can call it anything you like If the column is not present or if updated col is empty no special processing occurs php class Vendor Model Foo extends Vendor Sql Model public function setup use a column called last changed as the updated timestamp column this updated col last changed 3 8 3 Auto Sequence The sequence cols property notes one ore more table column to be automatically populated with the value of a sequence when the column is null The key is the column name and the value is the sequence name If only a value is present it is used as both the column name and the seqence name php class Vendor Model Foo extends Vendor Sql Model public function setup when bar is empty popualate it with the next value from the sequence zim this sequence cols bar zim when dib us empty populate it with the next value from the sequence also called dib this sequence cols dib 3 8 4 PHP Serialize The serialize cols property identifies columns that should be serialize d when saved to the database and unserialize d when they are retrieved This allows you to seamlessly use an array as a record property php class Vendor Model Foo extends Vendor Sql Model public function setup the column user prefs should be serialized on save and unserialized on retrieval this serialize cols user prefs 3 8 5 XML Structs

    Original URL path: http://solarphp.com/manual/model.columns (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    right kind of object for you when you fetch from it By default the model will look for a column named inherit php class Acme Model Contents extends Acme Sql Model protected function setup this inherit col inherit Here is an example of a database table set up for single table inheritance the table is called contents Table 3 2 Example Single Table Inheritance Data id inherit author title slug body 1 Articles pmjones Article Subject article subject The text of the article 2 Reviews bolivar Review Title review title The text of the review 3 Wikis gir Wiki Page Name Wiki Page Name The text of the wiki page 3 9 2 Extend the Model Now that we have a contents table and a model for it we need to have models for the different inheritance types in it Use make model as you would with a regular table but add a extends flag to indicate that the new model classes should extend from our contents model script solar make model Acme Model Articles extends Acme Model Contents script solar make model Acme Model Reviews extends Acme Model Contents script solar make model Acme Model Wikis extends Acme Model Contents 3 9 3 Fetching Fetching records and collections from inheritance models works just as with non inheritance models The classes will all use the same table as the parent model but will automatically restrict themselves to rows of their own inheritance type php var model Solar Sql Model Catalog fetch all articles records from the contents table only articles model articles fetchAll fetch all reviews records from the contents table only reviews model reviews fetchAll fetch all wikis records from the contents table only wikis model wikis fetchAll You can even fetch all inheritance types at once using the

    Original URL path: http://solarphp.com/manual/model.sti (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    4 4 1 Setup 4 4 2 SQL for Lazy Load 4 4 3 Foreign Key 4 4 4 Relationship Definition 4 5 Native Model Belongs To Related Foreign Model 4 5 1 Setup 4 5 2 SQL for Lazy Load 4 5 3 Foreign Key 4 5 4 Relationship Definition 4 6 Native Model Has Many Related Foreign Records Through An Association 4 6 1 Setup 4 6 2

    Original URL path: http://solarphp.com/manual/related (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    itself is useful but it is almost always the case that a model does not really stand alone Usually each model will relate to other models in some way This chapter goes over how to set up relationships between model objects and how to work with them Prev Up Next Chapter 4 Working With Related Models Home 4 2 Domain Description Local Navigation Home Project Packages Classes Manual Bugs Copyright

    Original URL path: http://solarphp.com/manual/related.intro (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    the content of the blog entry Comments Each of the many comments in the system is attached to only one blog entry Tags Each tag has one or more blog entries associated with it Summaries Each summary is attached to only one blog entry 4 2 2 Terminology In Solar terms we can more formally say the following about the domain An Author has many Blogs This is a one to many relationship A Blog entry belongs to an Author This is a one to one relationship A Blog entry has many Comments This is a one to many relationship A Blog entry has many Tags associated with it and at the same time belongs to those tags This is a many to many relationship A Blog entry has one Summary line This is a one to one relationship A Comment belongs to a Blog entry This is a one to one relationship A Tag has many Blog entries associated with it and at the same time belongs to those blog entries This is a many to many relationship Based on that language we can see the four types of relationships that Solar recognizes in the above example superior one

    Original URL path: http://solarphp.com/manual/related.domain (2016-02-13)
    Open archived version from archive

  • Solar Framework for PHP 5
    one relationship the foreign key exists in the foreign model table In our example domain this means the foreign key for the related blog is on the summaries table and maps to the primary key on the blogs table Foreign Column Naming Each model defines for itself what it expects its foreign column name to be when it is used as a foreign model in a relationship Native models then ask the foreign model what the foreign model expects to use as a foreign column name By default models define their expected foreign column name as a singular form of their table name appended with their primary key For example if the model table name is authors and the primary key on the authors table is id the authors model will default to saying its foreign column should be called author id You can change that value by editing the foreign model setup to add this foreign col something else 4 3 4 Has One Or Null When the foreign data does not exist at the database the Solar model system will create a new related record for you in the main record object when you attempt to get or set that related record Sometimes this automatic record creation is not what you want In those cases you should define the relationship as hasOneOrNull In a has one or null relationship a null will be placed in the related property instead of a new record object When you access it you will need to check it yourself to see if a record object is present 4 3 5 Relationship Definition Although the Solar model system makes some assumptions about how tables and foreign keys are named these assumptions are not hard coded You can define every aspect of the foreign relationship using an array of key value pairs passed to the hasOne method php this hasOne name array option value string foreign name Normally the model system expects the foreign model to be in the catalog uner the plural form of the related name E g native hasOne foreign means the catalog name foreigns which will map to some model class Use the foreign name option to specify a different catalog name for the foreign model This allows you to name the relationship foo and thereby the record property for the foreign but use the catalog name bar to do the work The foreign class option takes precedence over foreign name string foreign key Normally the model system expects the foreign key on the foreign table to be the same as the one defined by the native model s foreign col value Use the foreign key option to specify a different column in the foreign table This option will be ignored if a specific native col or foreign col option is set array cols Fetch these columns for the related records array conditions Additional conditions on the foreign table when fetching related records These will be used as WHERE conditions

    Original URL path: http://solarphp.com/manual/related.has-one (2016-02-13)
    Open archived version from archive



  •