![]() |
Need help with image script - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Need help with image script (/showthread.php?tid=39400) |
Need help with image script - El Forum - 03-09-2011 [eluser]Unknown[/eluser] I cant get this script to work in codeingniter. Ive tried different paths for images but it just doesnt find any. Last echo is executed. "Images cannot be found". //controller Code: $this->load->model('loadimages'); Code: <?php $this->loadimages->printimages($this->uri->segment(3)); ?> //model Code: <?php Need help with image script - El Forum - 03-10-2011 [eluser]egunay[/eluser] First of all I see that you are accessing your model directly from your view which isn't the best way to do things. Secondly, models are PHP classes that are designed to work with information in your database. So if you are not going to connect to a database and select, insert, delete etc. stuff don't use it. Instead do it in your controller or create a library. If you are using ".htaccess" be sure that you add your images folder in the exceptions: RewriteEngine on RewriteCond $1 !^(index\.php|images|css|something else...) RewriteRule ^(.*)$ /index.php/$1 [L] Need help with image script - El Forum - 03-10-2011 [eluser]Unknown[/eluser] Thank you for your answer egunay. I created a library for the image script. I also got it to work with a few changes. Now when the script works its nicer to start improving it. You said that i should not access my model directly from my view. I guess its same with library... Maybe i try to modify that next. here is the code: //view Code: <?php $this->loadimages->printimages($this->uri->segment(3), base_url()); ?> //controller Code: $this->load->library('loadimages'); //library Code: <?php Need help with image script - El Forum - 03-10-2011 [eluser]egunay[/eluser] Your welcome, Using a model from library is a bit more difficult then using it in your view. I mean you have to get CI instance: In your library: Code: <?php And if you want to make things still more MVC style, In your controller Code: $this->load->library('loadimages'); In your view Code: <?php |