Welcome Guest, Not a member yet? Register   Sign In
generate pages and links
#1

[eluser]trevor2[/eluser]
I need to write something that will generate links and pages as needed. Not really sure how to best go about it. Guess I would need three views matching the URI structure: directory_view, subdirectory_view, pagenumber_view. Then a matching function for each view. Is this making sense? How do you pros go about it?

The URL would look like: website.com/directory/subdirectory/pagenumber. The links and all information in the pages would be come from the database. So far I'm looking at using these functions: uri_string(), anchor()

Here is the initial code that I have.

Controller
Code:
class Portal extends Controller{
function directory()
    {
        $this->load->database();
        $this->load->helper('array');
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->model('Submit_model');
        
        /* hard code a category id for now */
        $idnumber = 1;

        /* $data['voodoolinks'] = $ */

        $data['a_list'] = $this->submit_model->state_directory($idnumber);
        $this->load->view('directory_view', $data);
    }
}

Model
Code:
class Submit_model extends Model {
function state_directory($idnumber)
    {
        $query = $this->db->get_where('tablename',array('thefieldname'=>$idnumber));
        return $query;
    }
}

View
Here the links need to be made automatically by getting the result from a query.
Currently displays all results from a query by the id number of a category

Code:
<?php foreach($a_list->result() as $row):
echo '<div class="box">' . '<br>';
echo '<div class="leftbox"><b>'  . 'Title' . ' ' . '</div></b>' . '<div class="rightbox">'  . $row->title . '</div>' . '<br>';
echo '<div class="leftbox"><b>'  . 'Description' . ' ' . '</div></b>' . '<div class="rightbox">'  . $row->description . '</div>' . '<br>';
echo '<div class="leftbox"><b>'  . 'Website Address' . ' ' . '</div></b>' . '<div class="rightbox">'  . anchor($row->url) . '</div>' . '<br>';    
echo '</div>';      
endforeach;?&gt;
#2

[eluser]obiron2[/eluser]
CI's 'standard' URI segments are Contoller/Function/Parameters.

Although you can override this using htacces or routes(), you would be losing a lot of functionality.

Is there any particular reason why you need the URI to be Directory/SubDirectory/Page.

you would do better (from a CI point of view) to 'Portal'/'Subportal'/portal_id/page_no/portalname/pagename

'Portal' is your controller
'Subportal' is a function in 'Portal' which accepts parameters portal_id and page_no

portalname and pagename are 'dummy' parameters that make your URL search engine friendly but are not actualy used.

so your full URL might look like the following

www.mydomain.com/Portal/subportal/17/4/Milan/Shopping
www.mydomain.com/Portal/subportal/22/5/Paris/Nightlife

You can then use this standard format to build your list of links.


Not a full answer, but I hope it helps
#3

[eluser]trevor2[/eluser]
I get what you mean.

My trouble seems to be this:
I'm having really difficult time understanding the redirection code that takes place. In that, a unique content page is created and displayed in a single reusable view and their associated to the links of another page.

I went through the blog videos and sort of got it at the time with the comments section, but it's gone.
#4

[eluser]Joel Wallis[/eluser]
Sorry, but i do not understand what exacly you want, but, routings in CodeIgniter is fully costumizables.
You can, for example, create a route to some controller, that will search it into your database.

For example, you can setup some route to the Pages controller, and these controller will search on the database the page data, and load the template to show it in the browser.

Have you already read about uri routings?




Theme © iAndrew 2016 - Forum software by © MyBB