Passing variables question |
[eluser]ChrisF79[/eluser]
I'm learning CodeIgniter and have a basic question regarding passing variables around. Basically, I want to query my database in my property_model to get one property for sale. That part works. But, I want to then build the page's <title> tag using the information from the query. Where do I actually do the building of the title and how do I go about doing it? Any help is greatly appreciated! <b>SITE</b> Code: function property() { <b>MODEL</b> Code: /*********************************************************************/
[eluser]TWP Marketing[/eluser]
[quote author="ChrisF79" date="1345403304"]I'm learning CodeIgniter and have a basic question regarding passing variables around. Basically, I want to query my database in my property_model to get one property for sale. That part works. But, I want to then build the page's <title> tag using the information from the query. Where do I actually do the building of the title and how do I go about doing it? Any help is greatly appreciated! add a line in the controller to load the title var: <b>SITE</b> Code: function property() { Code: ...
[eluser]ChrisF79[/eluser]
The part where I pass the variable to my view is fine. The part I can't figure out is how to use the results of the query in the title of the page.
[eluser]TWP Marketing[/eluser]
The query was parsed into an array of rows an that was put into $data['records'] That array will be exploded by CI and made available to the view as the array: $records Before you call the view, you have all those rows of data in $data['records']. I don't know which piece of data you want to put into the header meta 'title'. I suggest that the information is not in $data['records'], since the title is just a text about the page. If your db is a set of MLS listings, then you can compose the title text yourself, for instance: Code: <meta name='title' content='MLS Listing of Houses' /> If you want to get more specific, then the title needs information such as the 'MLS Listing id' which was used in the WHERE clause of the query string. Can you tell me what, exactly, you want to be in the meta title content?
[eluser]Samus[/eluser]
[quote author="ChrisF79" date="1345410688"]The part where I pass the variable to my view is fine. The part I can't figure out is how to use the results of the query in the title of the page.[/quote] Code: $data['records'] = $this->property_model->getOneProperty($data['mls_listing_id']); All you have to do in your view is something like this: Code: $records->fieldname. Code: ... You get the jist.
[eluser]ChrisF79[/eluser]
[quote author="Samus" date="1345411922"] All you have to do in your view is something like this: Code: $records->fieldname. You get the jist.[/quote] Now we're onto something. In my view, I have a simple print_r($records) that spits out the data. It is getting passed through just fine. However, I tried updating my controller to the following and it didn't work: Code: function property() { That's not working out. You can see what I'm trying to do at http://listingnaples.com/site/property/2...s-fl-34108
[eluser]Samus[/eluser]
[quote author="ChrisF79" date="1345413301"][quote author="Samus" date="1345411922"] All you have to do in your view is something like this: Code: $records->fieldname. You get the jist.[/quote] Now we're onto something. In my view, I have a simple print_r($records) that spits out the data. It is getting passed through just fine. However, I tried updating my controller to the following and it didn't work: Code: function property() { That's not working out. You can see what I'm trying to do at http://listingnaples.com/site/property/2...s-fl-34108[/quote] Because '$records' isn't defined yet. It gets defined when it's exploded in your view. So use it in your view.
[eluser]TWP Marketing[/eluser]
[quote author="ChrisF79" date="1345413301"] Code: function property() { Look at the new line to see how to access the $data array inside the controller, BEFORE it is sent to the view and exploded (see php.net for the explode function). |
Welcome Guest, Not a member yet? Register Sign In |