Welcome Guest, Not a member yet? Register   Sign In
newbie need ur help!!
#1

[eluser]wissal[/eluser]
Hi
im new to codeigniter and to mvc
i need to create a website and im having trouble starting
i want to have a menu on the first page (home) , it would be something like this :

+home +services +products +contact +login
|_sub menu1
|_sub menu2

i have already followed a tutorial and created a login page which call my home page..
when i try to call another page from the home it says this page does not exist although i have it in my views,for that i used load->view i also used the normal <a > and anchor!!
and in the url i get localhost/c/index.php/login/home i dont know why i get login i should not i think this is why it says it doesnt exist..

now i need to start with home page and have the login page in the menu like i showed u,
my problem is that i dont know how to add links so i can navigate between the pages..plz help me, i need to find a solution today


i hope i was clear
plz bare with me and explain to me step by step
thanks
#2

[eluser]iConTM[/eluser]
A quick solution could be this:

Code:
$menu = array(
array(
  'name' => 'home',
  'url' => base_url() . 'home', // reference to the controller
  'children'
    => array(
     array( 'name' => 'sub menu1', 'url' => base_url() . 'home/smenu1' ), // where smenu1 is the function within the home controller
     array( 'name' => 'sub menu2', 'url' => base_url() . 'home/smenu2' )
    )
),
array( 'name' => 'products ', 'url'=> '', 'children' => array() ),
array( 'name' => 'contact ', 'url' => '', 'children' => array()),
array( 'name' => 'login', 'url' => '', 'children' => array())
);

for the HTML:

Code:
<ul class='menu'>

&lt;?php foreach ($menu as $item) : ?&gt;
<li><a href="&lt;?php echo $item['url'] ?&gt;">&lt;?php echo $item['name'] ?&gt;</a></li>

&lt;?php if ( is_array($item['children']) && count($item['children']) > 0 ) : ?&gt;
<ul>

&lt;?php foreach ($item['children'] as $subitem) : ?&gt;
<li><a href="&lt;?php echo $subitem['url'] ?&gt;">&lt;?php echo $subitem['name'] ?&gt;</a></li>
&lt;?php endforeach; ?&gt;

</ul>
&lt;?php endif; ?&gt;

&lt;?php endforeach; ?&gt;
</ul>
#3

[eluser]wissal[/eluser]
i already have a template with the menu ready and all the pages, and a js script for sub menus..all i need is how to add the links so i can naviguate between my pages
using <a > didnt work for me i dont know why!
#4

[eluser]iConTM[/eluser]
Code:
<a href="&lt;?php echo base_url() ?&gt;controller/class/param1">link</a>

is your .htaccess file configured correctly?

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#5

[eluser]wissal[/eluser]
im testing in local , i dont have the .htaccess in local
i dont really understand how it works exactly, i used it just to add a password on the page..so i didnt understand what u wrote
anyway here is what i have in it on the server:

Code:
Options -Indexes
AuthUserFile /home2/netwioco/public_html/.htpasswd
AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>


what do u mean by param1 ??
Code:
<a href="&lt;?php echo base_url() ?&gt;controller/class/param1">link</a>
and why would i point to the controller while i want to load the view and my page is in the view folder??
#6

[eluser]iConTM[/eluser]
well i'm not a .htaccess hero either :p

did you try to set 'index.php' in the url you want to access?
e.g.: http://localhost/index.php/hello

I know that you can define which directories or files can be accessed or not by the user.
This is a verry important file when setting up CI.

here are some interesting links about this:
http://ellislab.com/codeigniter/user-gui.../urls.html
http://opinionatedcoder.wordpress.com/20...-htaccess/

the function parameters can be passed by url
e.g.

Code:
<a href="&lt;?php echo base_url() ?&gt;home/article/15">link</a>

home = controller
article = method
14 = param for article method (optional)

Code:
function article ($id)
{

}

Quote:and why would i point to the controller while i want to load the view and my page is in the view folder??

This is how CI works:

the view is loaded within each controller
each controller can be accessed by the url

it's all explained in the userguide Smile
#7

[eluser]wissal[/eluser]
thank you
i will look at the links u gave me tomorrow morning

i tried to put the index directly in the url but didnt work

"the view is loaded within each controller..each controller can be accessed by the url"
i know that..
so u mean that i should create a controller for each view i have so i can load it from there,right?
so many controllers/files for all the views i have with just the load function in each of them!!
#8

[eluser]iConTM[/eluser]
you can load multiple views in one controller.

you can see a controller as a category or directory

Code:
&lt;?php

class Articles extends Controller {

    function Articles ()
    {
        parent::MY_Controller();
        #load model to access article data (models/article_model.php)
        $this->load->model('Article_model');
    }

    // accessed by '/articles'
    function index()
    {
        $this->latest();
    }

    // accessed by '/articles/article/id'
    function article ($id)
    {
        #collect data for view
        $data['title'] = 'Some title'
        $data['article'] = $this->Article_model->get_article($id);
        #show the view (views/single-article.php)
        $this->load->view('single-article', $data);
    }

    // accessed by '/articles/latest'
    function latest()
    {
        #collect data for view
        $data['title'] = 'Some title' // view data
        $data['articles'] = $this->Article_model->get_latest_articles();
        #show the view (views/all-articles.php)
        $this->load->view('all-articles', $data);
    }

}

/* End of file articles.php */
/* Location: ./system/application/controllers/articles.php */




Theme © iAndrew 2016 - Forum software by © MyBB