Welcome Guest, Not a member yet? Register   Sign In
Page navigation in view file
#1

[eluser]Tanvir[/eluser]
Hello, I m new to CI. I want to know how to navigate to a page from view file.

Should I use the simple link -
Code:
<a href="detail.php">Detail</a>
- in a view file to link to another page?

Should I use the CI segment-based approach to link to a new file ?

One more thing, can I use php built-in functions and properties (not CI classes,functions) anywhere in controller,view and model class ?
#2

[eluser]jblack199[/eluser]
URI in Codeigniter is 'different' than any other system especially stand alone php...

Think of the URL setup for CI as if you were using a switch... but you can also use a switch inside of a switch, and keep going deeper...
Code:
switch {
default:
break;

case other:
  switch {
   default:
   break

   case 2:
   break;
}
break
}


in that your uri would be index.php?something=something or index.php?something=something&something_else=something_else..

well it's the same thing in CI, except its more search engine friendly. If you're using .htaccess to remove the index.php you never have to have .php in any of your links...

so if you're hard coding your navigation it'd be more like: http://www.domain.com/other/2 as based on my 'switch' code that has a few syntax errors in it. but if you're not using .htaccess it would be index.php/other/2 and you'd still get the same effect.

However, I would recommend using the anchor function in the uri helper (i think), to create your links for you dynamically so they always fit the current codeigniter configuration.
#3

[eluser]Tanvir[/eluser]
Thnx bro.

If I hardcode the url in view file, should I use the relative path (user/profile.php) from the controller class or the absolute path - www.mysite.com/home/user/profile.php

Can I use this uri helper in view file to dynamically create links.

One more thing, though out of context, I m a bit confused about the fact that if I use the php view file, how can I use javascript/jquery or css in php file?

Even, I used an external css file in my html view file and put that css into the view folder but the css file is not working, though the html is showing up, without any effect of the css.
#4

[eluser]jblack199[/eluser]
if you hard code it http://www.mysite.com/home/user/profile.php you'd need to make sure that in your config.php you have $config['url_suffix'] = 'php';

you can use the url helper in the view file yes. You would load it in your controller, and use the syntax of the anchor() function in the view file.

i would suggest (if you haven't done it yet) that in your config.php you set $config['base_url'] = 'http://yoursite.com/';

Javascript, and CSS should be in the root folder. I have mine in and inc folder in the root and since i am using .htaccess I have
Code:
RewriteCond $1 !^(index\.php|inc|robots\.txt)
as my second line in my .htaccess to grant permission to the inc folder.

then in your view files, you can link your javascript or css like:

Code:
&lt; script type="text/javascript" src="&lt;?php echo base_url(); ?&gt;inc/js/custom.js"&gt;&lt;/ script>
    &lt; link href="&lt;?php echo base_url(); ?&gt;inc/css/adm/ui.base.css" rel="stylesheet" media="all" /&gt;
#5

[eluser]Tanvir[/eluser]
Thnx...

What if I hardcode url this way http://www.mysite.com/home/user/profile
without any .php extension , do I need to modify $config[‘url_suffix’] then ?

I dont have any knowledge about .htaccess . Though I know that it controls the access mechanism. I dont use any .htaccess file. So, now how m I gonna do this ?

Why cant I put css/js into view folder and use a relative path from view folder ?

man..this CI things feel more complicated than regular php coding.....sigh..




Theme © iAndrew 2016 - Forum software by © MyBB