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
    you will generate 10 additional SELECT queries one for each related blog for a total of 11 queries To avoid this eager fetch the related comments when you fetch the blog collection more on eager fetching in a later section 4 4 3 Foreign Key In a has many 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 comments 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 4 4 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 hasMany method php this hasMany names 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 hasMany foreigns 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 or as JOIN ON conditions as appropriate for the kind of fetch being performed e g lazy vs eager fetch array order Additional ORDER clauses when fetching related records Note The following are some less common but more advanced and more finely grained options for defining relationships string foreign class The class name of the foreign model

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


  • Solar Framework for PHP 5
    record author name each time you will generate 10 additional SELECT queries one for each related author for a total of 11 queries To avoid this eager fetch the related author values when you fetch the blog collection more on eager fetching in a later section 4 5 3 Foreign Key In a belongs to relationship the foreign key exists in the native model table In all other related types the foreign key exists in the foreign model table In our example domain this means the foreign key for the related author is on the blogs table and maps to the primary key on the authors 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 5 4 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 belongsTo method php this belongsTo 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 belongsTo 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 native table to be the same as the one defined by the foreign model s foreign col value Use the foreign key option to specify a different column in the native 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 or as JOIN ON conditions as appropriate for the kind of fetch being performed e g lazy vs eager fetch array order Additional ORDER clauses when fetching related records Note The following are some less common but

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

  • Solar Framework for PHP 5
    record tags each time you will generate 10 additional SELECT queries one for each related blog for a total of 11 queries To avoid this eager fetch the related tags when you fetch the blog collection more on eager fetching in a later section 4 6 3 Foreign Key In a has many through relationship the foreign key exists in the through association model table and identifies which mappings belong to the native model In our example domain where a blog has many tags through taggings this means the blog foreign key blog id is on the taggings table and maps to the primary key on the blogs table Similarly where a tag has many blogs through taggings the tag foreign key tag id is on the taggings table and maps to the primary key on the tags table 4 6 4 Through Key In a has many through relationship there is a second foreign key to keep track of the through key The through key exists in the through model table and identifies which mappings belong to the foreign model In our example domain where a blog has many tags through taggings the through key tag id is on the taggings table and maps to the primary key on the tags table Similarly where a tag has many blogs through taggings the through key blog id is on the taggings table and maps to the primary key on the blogs table 4 6 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 hasManyThrough method php this hasManyThrough foreigns mappings 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 hasManyThrough foreigns mappings means the foreign model on the other side of the mapping relationship uses the catalog name foreigns Use the foreign name option to specify a different catalog name for the foreign model on the other side of the related mappings 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 foreign model s primary 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 string through key Normally the model system expects the through key on the through table to be the same as the one defined by the foreign model s foreign col value Use the through key option to specify a different

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

  • Solar Framework for PHP 5
    and the N is all the extra individual lazy load queries Lazy loading related data is convenient but if you know in advance that you re going to need certain related data you should eager fetch it to reduce the number of queries involved To perform an eager fetch specify the names of the relateds you want to retrieve php var Solar Sql Model Catalog model list model blogs fetchAll array page 1 paging 10 eager array author summary eager fetch foreach list as item echo Blog ID htmlspecialchars item id by htmlspecialchars item author name has htmlspecialchars item summary comment count comments br Now only one query will be issued Because author and summary are to one relationships the Solar model system will LEFT JOIN them to the blogs query merging the data into a single result set at the database and then emerge the related data into their own objects in PHP While to one relateds are joined into the original result set to many relateds generate one additional query per relationship This is not the same as N 1 no matter how many records are in the original result set there will be only one additional query for each to many related For example to also get the tags and comments on the blog listing you would do the following php var Solar Sql Model Catalog model list model blogs fetchAll array page 1 paging 10 eager array author summary comments tags This generates a total of three queries one for the blogs listing with author and summary joined in one for all comments on the blog result sets and one for all tags on the blog result set If we had done this by lazy loading each of the relateds in a loop across the blogs

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

  • Solar Framework for PHP 5
    them directly instead of fetching a new record from the related model and attaching it php var Solar Sql Model Catalog model var Acme Model Blog Record item if item comments item setNewRelated comments you could do this to add a new comment comment model comments fetchNew comment body A new comment item comments comment but this may be easier comment item comments appendNew array body A new comment To save a record and all its subordinate records and collections invoke the save method on that record This will not save superior belongs to records those you must save on your own php var Acme Model Blog Record item set a value on the related summary record item summary last comment at date Y m d H i s save the blog record including all subordinate has one has many and has many through relateds item save the item author property will not be saved it is a superior belongs to related not a subordinate 4 8 1 Automatic Foreign Key Management For has one and has many relateds the Solar model system will automatically set the proper foreign keys in the related records and collections for you when you save the record However when you have a new belongs to related you must save it yourself before you attempt to save the subordinate record This is because the superior record to which the subordinate record belongs does not have a primary key yet If you try to save a record where the record it belongs to does not exist in the database it will throw an exception Finally for has many through relationships the Solar model system manages the association mapping table for you All you need to do is add to the foreign collection on the record New

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

  • Solar Framework for PHP 5
    3 2 Option 2 Use the Solar View partial method 5 4 Alternate Formats 5 5 View Helpers 5 6 Layouts 5 6 1 Specify the Default Layout 5 6 2 Create the Default Layout 5 6 3 Create the head php Sub Layout 5 6 4 Create the body php Sub Layout 5 6 5 Create the header php and footer Sub Layouts 5 6 6 Create the nav

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

  • Solar Framework for PHP 5
    be passed This maps to Acme App Blog actionRead 1 in SYSTEM source acme Acme App Blog php Which outputs to SYSTEM source acme Acme App Blog View read php Solar expects to find view scripts in predefined locations The default directory structure for the Acme vendor with a single blog application looks like the following Acme App Blog Layout Locale Public View Blog php Controller Bread Layout Locale Public View Page Layout Locale Public View Bread php Page php Model Sql Filter php It should be reasonably obvious from this structure where views and layouts are expected to be found The blog application expects to find its views and layouts in SYSTEM source acme Acme App Blog View and SYSTEM source acme Acme App Blog Layout respectively That is straighforward enough however if you open the SYSTEM source acme Acme App Blog php file in your favorite editor you will notice that the Acme App Blog class extends Acme Controller Page This is important because it influences the class stack the hierarchy where Solar looks for files In this case Solar first looks for views in SYSTEM source acme Acme App Blog View and if it doesn t find

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

  • Solar Framework for PHP 5
    is passed as an argument Also all the properties of the parent view are available to the nested view 5 3 2 Option 2 Use the Solar View partial method h1 Example Page h1 php view script index php add a another view as a partial echo this partial list this list adding the php extension is optional This method is similar to the Solar View template method but here

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



  •