Welcome Guest, Not a member yet? Register   Sign In
Alter an object
#1

[eluser]überfuzz[/eluser]
Situation: A method in a model is fetching info from a database. I call this method in a controller sending a url-segment as an argument. This is to get pageinfo. Now I'm having a hard time getting the info in the shape I want it. The info is pasted to $this->data['page_contents'] as an array. With my limited skill I can't alter data. I would like to separate page_contents. Like this.

page_contents (just an example)
Code:
Array(
[0] Array(
   [page] = Start
   [title] = Welcome
   [text] = Lorem ipsum...
   )
[1] Array(
   [page] = Start
   [title] = Hi again
   [text] = Ut enim ad...
   )
)

Now I'm ending up with a solution thats somewhat questionable.
The view-file:
Code:
foreach($page_contents AS $row)
{ echo $row->page; break; }

The controller I'm tinkering with:
Code:
$url_segment = $this->uri->segment(1, 'home');
$this->data['page_contents'] = $this->pagesdata->get_page_content($url_segment,1);

$data['header'] = $this->load->view('view_html_head', $this->data, true);
$this->load->view('view_index', $this->data);
#2

[eluser]Phil Sturgeon[/eluser]
Instead of returning all records with $query->result() you need to select only one page result and return that. You have $url_segment so in get_page_content() do something as simple as:

Code:
function get_page_content($slug)
{
    $query = $this->db->getwhere( 'pages', array('slug' => $slug) );
    return $query->row();
}

That will return a single page and stop you having to run through all the records to find the right row.
#3

[eluser]überfuzz[/eluser]
Well you got a point, that was one option I was going for. However, I need the other stuff two. So that would make two querys and that felt... queery. It wasn't the render speed I was worried about, merely the fact that it is irritating that I can't make it work with one query...

Thanx!!! I'll go with your solution for now...
#4

[eluser]depthcharge[/eluser]
Seems to me that you would benefit from using 2 tables here for the sake of normilization.

I am presuming you are using just 1 table?

for example (fields here just for example)

a) page (page_id,url/title/meta,keywords/description etc) - page info
b) page_content (content_id,page_id,content etc) - content blocks etc.

You could query for a single page/url and get data from both the tables in 1 query (joining the tables, results would look similar to your current results) or 2 queries (1 result for the page, another result for the content blocks etc) depending on how you decide to do it.
#5

[eluser]überfuzz[/eluser]
[quote author="lee74" date="1241545284"]Seems to me that you would benefit from using 2 tables here for the sake of normilization.[/quote]
I do actually; pages and page_content. But I've got link_tags, meta etc in the config-file.




Theme © iAndrew 2016 - Forum software by © MyBB