Welcome Guest, Not a member yet? Register   Sign In
  Getting a blank white page when using a model to connect with db
Posted by: El Forum - 09-01-2007, 09:29 PM - No Replies

[eluser]exceedstudios[/eluser]
I'm fairly new to CI and I've been having alot of trouble trying to use the MVC when trying to use database functionality. I have no problem when I do it just with the controller and view. I keep getting that blank white page when I try to load some fields from my db.

This is my code:

The Model:

Code:
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Homemodel extends Model {

    function Homemodel()
    {
        parent::Model();
    }
    
    function musicvideos()
    {
        $query = $this->db->get('clips', 4);
           return $query->result();
    }
    

}


Controller:
Code:
class Home extends Controller {

    function Home()
    {
        parent::Controller();
    }

    function index()
    {
        $data['title'] = "Welcome";
        
        $this->load->model('homemodel', '', TRUE);
        $data['query'] = $this->homemodel->musicvideos();
        
        $this->load->view('home_view', $data);
    }
}

The View
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>

<?php foreach($query->result() as $row): ?>

    &lt;?php echo $row->filename; ?&gt;<br>

&lt;?php endforeach; ?&gt;

&lt;/body&gt;
&lt;/html&gt;


  Validation Bug
Posted by: El Forum - 09-01-2007, 11:59 AM - No Replies

[eluser]adamp1[/eluser]
I was writing a new form for my website, when I needed to check first if a date was in the correct format, then if it was not in the past so I created the following code:

Code:
$rules['expire'] = 'callback_dateformat|callback_dateinpast';        

function dateformat($str)
{
  $this->validation->set_message('dateformat','The %s is not in the format DD/MM/YYYY');
  return (ereg('[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}',$str)) ? TRUE : FALSE;
}

function dateinpast($str)
{
  $this->validation->set_message('dateinpast','The %s cannot fall in the past');
  list($day,$month,$year) = explode('/',$str);                
  $unixtime = mktime(0,0,0,$month,$day,$year);        
  return ($unixtime>=time()) ? TRUE : FALSE;    
}
(Of course this isn't how my file is structured)

So now if I don't enter a correct date I get the first error, but if I enter correct date but one in the past I don't get an error. Now I know were the problem is. If I have the following field rule.

Code:
$rules['expire'] = 'required|callback_dateformat|callback_dateinpast';

It will work, since in Validation.php Line 279 it only moves on if the result is TRUE and its required. Otherwise it cuts out. Now its fine when only one callback is used but with two it breaks.


  Insert Error Message into view
Posted by: El Forum - 09-01-2007, 11:20 AM - No Replies

[eluser]stevefink[/eluser]
Hey all,

Is there anyway to insert my error message directly into the view instead of returning a 404 that looks like this:


An Error Was Encountered

Error Number: 1054

Unknown column 'bodystyle' in 'field list'

INSERT INTO vehicles (vin, type, year, price, mileage, transmission, ext_color, int_color, bodystyle, doors, drive_train, engine, wheel_base, load_rating, additional_opts, model_id) VALUES ('12345667890123456', 'New', '1979', '4500', '11600', '', 'Blue', '', 0, '4', 'AWD', '', '', '', '', '8')


I'd rather present the user with something like "An error has occured, please contact ...." and then I'd log the incident and review logs to see what actually happened, or I'd just mail the errors to me. Is there something in the user guide which might explain how I can go about doing that?

Thanks. :-)

- sf


  Using a model from another one
Posted by: El Forum - 09-01-2007, 10:49 AM - No Replies

[eluser]camille roux[/eluser]
hello,

I'd like to use a model from another one. I saw that it's not possible to load a model in another model.
Is there a way to do what I want? Is it ugly?

Thank you


  Creating dynamic Views
Posted by: El Forum - 09-01-2007, 04:49 AM - No Replies

[eluser]Higher Logic[/eluser]
Here's a scenario:

I have a blog. My URL structure looks like this:

http://www.domain.com/blog/

With CI, I'm going to have a view for this. Then let's say I have an entry:

http://www.domain.com/blog/my-first-post/

I've been trying to think of a way to get a dynamic URL segment (entry title) to be positioned after a view instead of doing something like this:

http://www.domain.com/blog/view/my-first-post/

Normally, I would set this all up like so:

http://www.domain.com/blog/index.php?slug=my-first-post

Where the index.php file would check for the $_GET['slug'] value to determine the post to grab from the database and output, and if no $_GET['slug'] variable existed, it would output the standard blog listing with a list of entries and excerpt of their content.

So my question is, how do you set something like this up with CI without setting up another view?


  automatically add some tabs to the beginning of my text which is getting from the database
Posted by: El Forum - 09-01-2007, 03:55 AM - No Replies

[eluser]杨帅[/eluser]
the text from form-----&gt;post to a controller-----&gt;insert into database-----&gt;query in another controller-----&gt;pass through the second parameter of loadview function-----&gt;in another view, i echo it out, but found it was add some tabs at the beginning of the text. i donno which step cause this, anyone can solve this problem? great thanks.
another question, how can i remove these tabs? i use ltrim() to remove it ,but failed, i just donno what is the second parameter, i tried '\t' and '\t.', both failed.


  Sessions in database
Posted by: El Forum - 09-01-2007, 03:50 AM - No Replies

[eluser]feri_soft[/eluser]
Whats the reason for putting sessions in the database when the ip is not checked and it couldnt be as there are dynamic ips. If someone changes his session value in the cookie and has the same user_agent data as the real owner of that session id? How the validation is actually done. It seems a bit unusable. Can you explain please? Thanks!


  Re-mapping URI segments when using sub-folders in /controllers
Posted by: El Forum - 09-01-2007, 03:49 AM - No Replies

[eluser]Matthew Pennell[/eluser]
I'm using a sub-folder for my controllers, so I can do:

http://www.example.com/sub-folder/controller/method/id

However, this means that the id passed through above is in $this->uri->segment(4) instead of segment 3 where it normally would be.

Is there any way to either:

a) Re-map the URI segments so 4 is 3 and so on; or
b) Use the routes.php re-mapping rules to map requests onto controllers in sub-folders while retaining the correct numbering of URI segments?

Smile


  How to use get_instance in PHP5?
Posted by: El Forum - 09-01-2007, 03:36 AM - No Replies

[eluser]Optimus Prime[/eluser]
Hi! I'm practicing in CI programming. I have a question about get_instance and how use it in PHP5. I want to use hooks to to check the uri at the pre_controller level.

I used this in the hook.php

Code:
$hook['pre_controller'][] = array(
                                'class'    => 'Testhook',
                                'function' => 'test',
                                'filename' => 'testhook.php',
                                'filepath' => 'hooks',
                'params'   => array()
                                );
in testhook.php:
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Testhook{

var $CI;
var $urisegment;

    function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->urisegment = $this->CI->uri->segment(1);  //<< Only for test.
    }
    
    function test()
    {
        echo "Your uri in segment 1: ".$this->urisegment
    }
}

?&gt;
Suppose that to access to the welcoming message I type:

localhost/testsite/index.php

(all the site is contained in a folder called "testsite" and the C.I. folder is inside in "testsite")

But I get:
Code:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: hooks/Testhook.php
Line Number: 11

Fatal error: Call to a member function helper() on a non-object in /opt/lampp/htdocs/testsite/framework/application/hooks/testhook.php on line 11

What's wrong? I have read several posts about get_instance. Maybe I missed something about the get_instance. but I can't get it... I admit that i'm newbie with C.I. and advanced PHP5 Object Oriented Programming.

I'm using Fedora 7 with XAMPP to test this framework.

I will appreciate for your help.


  How can I get out of the manual and into the actual application?
Posted by: El Forum - 09-01-2007, 02:25 AM - No Replies

[eluser]Unknown[/eluser]
I've just installed CodeIgniter and read the manual (since it was the only link on the page when I opened the URL where I installed it).

I'm now bored with the manual and would like to start doing some of the things that it was talking about but there seems to be no link to open the application? Even the 'Getting Started' page was no help?

Is there really an underlying application or is it just all hot air?!

Kind regards

Peter


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Why PHP is still worth le...
by InsiteFX
4 hours ago
Any user guid or video o...
by msnisha
Yesterday, 02:30 PM
MVC vs MVCS vs CodeIgnite...
by massimiliano1.mancini
Yesterday, 10:15 AM
Is hiring a digital marke...
by Markhenry123
Yesterday, 02:45 AM
my controller fails to fi...
by PaulC
Yesterday, 01:40 AM
My Library cannot see ses...
by InsiteFX
05-08-2025, 08:48 PM
update the framework to t...
by captain-sensible
05-08-2025, 12:14 PM
CodeIgniter Shield 1.0.0 ...
by Ayatorvi
05-08-2025, 06:06 AM
Update to 4.6.1
by serialkiller
05-07-2025, 11:58 AM
Can't create new database...
by paulbalandan
05-07-2025, 08:49 AM

Forum Statistics
» Members: 145,050
» Latest member: puneescorts1
» Forum threads: 78,382
» Forum posts: 379,421

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB