Welcome Guest, Not a member yet? Register   Sign In
  How to use Model
Posted by: El Forum - 10-16-2007, 02:17 AM - No Replies

[eluser]Unknown[/eluser]
Is there any one know how to use models to access the database, I wrote the following code, is there anything wrong about it.

Code:
<?php
class Blogmodel extends Model
{
    var $title = '';
    var $content = '';
    var $date = '';

    function _construct()
    {
    //Call the model constructor
    parent::Model();
    }

    /*function Blogmodel()
    {
        $this->load->database();
    }*/

    function get_last_ten_entries()
    {
        $query = $this->db->get('entries',10);
        return $query->result();
    }

    function insert_entry()
    {
        $this->title = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date = time();

        $this->db->insert('entries',$this);
    }

    function update_entry()
    {
        $this->title = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date = time();

        $this->db->update('entries',$this,array('id',$_POST['id']));
    }
}

The above gives the following error....

[error]

A PHP Error was encountered
Severity: Notice

Message: Undefined property: Blogmodel::$load

Filename: test/blogmodel.php

Line Number: 24


Fatal error: Call to a member function database() on a non-object in C:\wamp\www\CodeIgniter\system\application\models\test\blogmodel.php on line 24

[\error]

Plz help me...., actually I want to insert in database using models. If you have the code for inserting in database using model,view and controller, plz send it to me.


  chinese question: it is about code for saving message to database.GBK
Posted by: El Forum - 10-16-2007, 02:03 AM - No Replies

[eluser]fanxiaotao[/eluser]
My english is very bad, i am a chinese.
Not everyone like me.

I user php at the first.

My database is mysql.
When i was save message to database ,that like Video Demo.
The message had saved to database, But the code was error.

egg: I wanted to save "阿四大幅" ,but it was "闃垮洓澶у箙" in the database.

If you can konw what i say.

I hope somebody could gave me a good answer.

May be i just need modify a file, that my thinking.


  Excellent CI+Xajax Resource/Examples!!
Posted by: El Forum - 10-16-2007, 01:28 AM - No Replies

[eluser]jz[/eluser]
Hello All,

Thank Goodness for Alex! This guy has put together some great examples of using CI and Xajax together.

Check them out:
Site 1
Site 2

Hope this helps somebody else!

-moo


  very easy, but i am fool
Posted by: El Forum - 10-16-2007, 12:43 AM - No Replies

[eluser]nirbhab[/eluser]
hello frndz, i am new to MVC and CodeIgniter, i am pretty impressed with its working but i am facing lil problem i think u MVC gurus can easily help me out.

So, lets begin:

Controller:
<?php
class Blog extends Controller
{
function __construct()
{
parent::Controller();
}
function index()
{
$this->load->model('tut/blogmodel','name');
$this->name->hello();
}
}
?>

Model:
<?php
class Blogmodel extends Model
{
function __construct()
{
parent::Model();
}
function hello()
{
echo 'hello';
}
}
?>
ERROR:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Blog::$name

Filename: tut/blog.php

Please help me out from this simple problem who has made me idiot.


  Force HTTPS for certain controllers
Posted by: El Forum - 10-15-2007, 11:00 PM - No Replies

[eluser]Michael Roper[/eluser]
I am trying to be able to force certain functions in my controller to only be accessed over SSL... so if they are accessed by a HTTP url, they will be redirected to the HTTPS url (with any POST data still intact)... but I only want those to be redirected, and everything else can stay on non-SSL.

here is my current .htaccess rules...

Code:
RewriteEngine On
RewriteBase /

## these were my original rules
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php/$1 [L]

#### SECURE CERTAIN PAGES

## if they are already on the http site
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} secure/(register|activation|login|profile)
RewriteRule ^(.*)$ https://%{HTTP_HOST}/index.php/$1 [L]

## if they are already on the https site
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} secure/(register|activation|login|profile)
RewriteRule ^(.*)$ https://%{HTTP_HOST}/index.php/$1 [L]


#### UNSECURE THE REST

## if they are already on the http site
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !secure/(register|activation|login|profile)
RewriteRule ^(.*)$ http://%{HTTP_HOST}/index.php/$1 [L]

## if they are on the https site
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !secure/(register|activation|login|profile)
RewriteRule ^(.*)$ http://%{HTTP_HOST}/index.php/$1 [L]

it looks convoluted, but it seems to work... with the exception of the fact that the 'index.php' shows up in the url when switching between the ssl and non-ssl site.. which i dont really like..

can anyone suggest a better way to do this, or at least a way to tidy up the rules above? i'm not familiar enough with the rewrite rules to figure it out without breaking other things... also, is this something i could be doing with routes?


  using anchor around an image tag
Posted by: El Forum - 10-15-2007, 10:38 PM - No Replies

[eluser]Eric Cope[/eluser]
Hello, I am trying to create the following code:

Code:
<a href="some/url"><img src="some/img.jpg"></a>

I am trying to use:
Code:
anchor("some/url","<img src='http://url/to/photo'>");

It produces odd undesired results. It is actually printing the text from a previous anchor call. Here is what it produces:

Code:
<a href="correct/url" <img src='current/img/src/path'>>link text from previous anchor use</a>

notice the redundant ">"?

It looks like it is redisplaying the old title. This does not sound correct. Any ideas or tips/tricks?


  Image Multi-Thumb
Posted by: El Forum - 10-15-2007, 08:23 PM - No Replies

[eluser]MMCCQQ[/eluser]
hi!


i got a question. how can i upload a Image , to get Resize to 640x400 , a Thumb 125x125 AND Thumb 25x25??? how???


  Database config file
Posted by: El Forum - 10-15-2007, 07:34 PM - No Replies

[eluser]cinewbie81[/eluser]
Hi all,

Sorry i post it on another forum previously, think that this is the right forum for me to post.. so here's it again ::


[quote author="cinewbie81" date="1192469868"]Hi all,

The following is my setup.php controller clas:

Code:
class Setup extends Controller {

function Setup()
{
  parent::Controller();
  $this->load->helper(array('url','form','setting'));
  $this->load->model('dbmodel', 'sql', TRUE);
  $this->load->database();

}
    
function index()
{
  $this->load->dbutil();
  if ($this->dbutil->create_database('payroll'))   {
      echo 'Database created!';
  }
}

}


And the following is my database.php config:

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "password";
$db['default']['database'] = "payroll";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";

When function index() loaded, the following error message prompted out:
"Unable to select the specified database: payroll"

This error is because I bind the value 'payroll' to $db['default']['database'] in my config file. It can be easily fixed if i manually query 'Create Database payroll' in prior, but i don't want it to be this way cause i don't want all my client have to manually create the database first before they can use the system. Any solution ??[/quote]


  Blank page on server
Posted by: El Forum - 10-15-2007, 07:10 PM - No Replies

[eluser]Majd Taby[/eluser]
Hi, my website has two applications (frontend,backend), and it works fine on my local computer. Yet when I move to the shared server, the frontend application works fine, but the backend one doesn't.

It stops after Controller::Controller or any loading of anything...It doesn't make sense.

EDIT: Also, for some reason, it tries to access my file names when they're minimized, it doesn't like capitalization...but the frontend application requires the filenames of the controllers to be like the name of the contoller(with the capitalization)

EDIT 2: Also, I can't find any syntax errors...there shouldn't be any, it works fine on my local machine. When i upload it "as-is", i get errors that the controller files could not be found. Seems like it wants the names minimized, when i replace all the capital letters with small letters, i get a blank page...


EDIT 3: Sorry about all this, turns out error reporting isn't on...contacting host to see if there's a way to turn it on..I don't ever remember it being off...


  How can I control the acces to a page using routing and uri with a special behavior?
Posted by: El Forum - 10-15-2007, 07:02 PM - No Replies

[eluser]Optimus Prime[/eluser]
Hi!

I post this topic because I want to know your opinion about my problem and to know another alternatives for it before to write a large code. I tested some alternatives but I want to know if there another way to acommplish my goal.

I explain my problem:

- Suppose that I have many controllers, all of them have the "show" function and it uses a parameter "name".
- Suppose that doesn't exist the same name between the sections (or controllers, in this case).

An example is:

site.com/people/show/name
site.com/places/show/name
site.com/{others_controller}/show/name

So, the problem is that I want to create easy access for the visitors (shorts url). I mean that redirect to the full address . Ideally, I want two types for accesing (or to redirect to) a page. I show it as an example:

Redirection Type 1:

site.com/name --&gt; redirects to --&gt; site.com/people/show/name

and

Redirection Type 2:

site.com/people/name --&gt; redirects to --&gt; site.com/people/show/name

The redirection type 2 can be discarded, but at less I need the type 1.

An alternative that I tried is to make a function (named redirection) that search for the name and redirect to the right controller (or URI adress) and config the routes (config/routes.php) in this way (based in the previos example):


$route['people(.*)'] = "people$1";
$route['places(.*)'] = "place$1";
$route['{other_controller}(.*)'] = "{other_controller}$1";
...etc...

$route['(.*)'] = "/redirects/to/$1";

It work for Redirection Type 1, but no for Redirection Type 2. I guess that I need to write the functions in $route like:

$route['people/list(.*)'] = "people/list(.*)";

So this mean that I need to config the config.php many times and write all the functions names too?(when I need to add o delete sections) a route map. Am i right? Ideally, I want to avoid it.

Another alternative but I want to avoid it, is to write a code like this:

Code:
function controller_function($action, $params...) {
  if ($action=="action1") {
  }
  elseif ($action=="action2") {
  }
  ...

}

Unless there is no way to accomplish my goal I will code with this style. But I want to find a better solution because the site that I'm working will suffer many modifications (sections will be added or deleted with the time).

The best alternative that I wish to find is to configure CI to process the uri segments: if the controller segment does not exist (in the code), before to show the error page, check if this uri segment is a name parameter and if is a name that exist in a database, then redirect to the rigth controller and function. Is this posible?

Or there is another suggestion?. I'll pleased to read your answers! :lol:


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

Username
  

Password
  





Latest Threads
Update from 4.6.0 to 4.6....
by FlavioSuar
Today, 04:17 AM
Setting baseURL in Regist...
by petewulf1
Today, 03:20 AM
Sessions old files are de...
by InsiteFX
Yesterday, 10:30 PM
Ajax post failing with Ty...
by PaulC
Yesterday, 12:23 AM
intermittent smtp failure...
by InsiteFX
05-11-2025, 11:30 PM
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
05-10-2025, 10:33 AM
CodeIgniter Shield 1.0.0 ...
by timesprayer
05-10-2025, 05:22 AM
Website Traffic Drop Afte...
by InsiteFX
05-10-2025, 04:23 AM
Magic login link not work...
by InsiteFX
05-10-2025, 04:16 AM
Is codeigniter 5 upco...
by InsiteFX
05-10-2025, 04:10 AM

Forum Statistics
» Members: 145,830
» Latest member: DigitalesGeld
» Forum threads: 78,388
» Forum posts: 379,447

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB