Welcome Guest, Not a member yet? Register   Sign In
  Create a base Controller for my App problem
Posted by: El Forum - 09-05-2007, 04:36 AM - No Replies

[eluser]Stefano G[/eluser]
Hello,
I am a Java/J2EE developer, and I am new to CI (although I develop php4 apps since 2001).

My current problem is that, I wanted to code my super controllers and models that could provide some convenience methods to be used in the "child" classes (I think this is the very first thing an OOP developer wants to do before even start coding a new app!).

This is the situation I'd like to implement (using php4 and CI 1.5.4):

application/controller/appcontroller.php

Code:
class AppController extends Controller
      ...

application/controller/controller1.php

Code:
class Controller1 extends AppController
      ...

as simple as 1 2 3? not at all! I received the "can't inherit from non existing class..." error when invoking the Controller1 class from my URIs.

What's wrong with that? I have read that I can not extend Models but what about Controllers?

Thank you for any kind feedback.

Stefano


  What could it be
Posted by: El Forum - 09-05-2007, 03:24 AM - No Replies

[eluser]E303[/eluser]
I have been developing this application on an apache/mysql/php installation on my vista laptop.

Anyway finally I uploaded it to my hosting space and sorted out all the little problem however there is a problem with the updateing of a database.

What worked perfectly before now dosen't seem to do anything.

The Model:

Code:
function Pages_update()
    {
        $data = array(
                    'title'                => $_POST['title'],
                    'meta_title'        => $_POST['meta_title'],
                    'meta_keywords'    => $_POST['meta_keywords'],
                    'meta_description'    => $_POST['meta_description'],
                    'internal'            => $_POST['subpage'],
                    'body'            => $_POST['body'],
                    'navTitle'            => $_POST['navtitle']
                    );
        $this->db->where('id', $_POST['page_id']);
        $this->db->update('pages', $data);
        

    }
The Controller:
Code:
function Pages_update()
        {
            $this->load->model('admin/Admin_Model');
            $this->load->model('Admin_Model');
            
            $this->Admin_Model->Pages_update();
            $data['query'] = $this->Admin_Model->Flakes_navigation();                
            $this->load->view('admin/main_admin_view', $data);
        }

Is there anything that I am missing?


  CI Validation
Posted by: El Forum - 09-05-2007, 02:12 AM - No Replies

[eluser]schnoodles[/eluser]
Hello everyone, i was in a little discussion about validation and purifieing today and it got me thinking.

When is CI Validation class not enough.

Also what does it cover, for example

1) if you use xss_clean should you still use something like mysql_escape_real_string()

2) should you have to purify your content with say HTMLPurifier incase it allows HTML

Im confused on where i would need more then CI as i just use xss_clean everywhere and thats really it, because basic validation like required / min_length / max_length / trim / matches

Has anyone else run into this problem, and can i get an example where they have ?


  small bug in _reindex_segments (Router.php)
Posted by: El Forum - 09-05-2007, 01:50 AM - No Replies

[eluser]El Oscuro[/eluser]
Hello ~

I believe I discovered a small (but for me it was very tough to find) bug in CI.

If we want to reroute something like http://myserver.com/blog/1 to http://myserver/blog/threads/1, it works fine.

But if the rerouted URI only differs from the original one in the order of segments (example: http://myserver.com/blog/users/1 => http://myserver.com/users/blog/1), _reindex_segments function mistakenly assumes them identical and as a result, there's no rerouting at all.

Here is the problem (Router.php, line 256):

Code:
// Is the routed segment array different then the main segment array?
$diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE;
And then...
Code:
if ($diff == FALSE)
{
    $this->rsegments = $this->segments;
}
Here is a quote from PHP's documentation:
Quote:array_diff() returns an array containing all the values of array1 that are not present in any of the other arguments.
This is not exactly what we want...
The problem is that array_diff doesn't care about order (in other words, keys) of segments in arrays.

I propose to use array_diff_assoc function here. I haven't tested it thoroughly but for now it works fine.

Hope this will be useful for someone! :coolsmile:


  Undefined index
Posted by: El Forum - 09-05-2007, 01:36 AM - No Replies

[eluser]abbe01[/eluser]
I have bumped into an error as while I have 2 submit button within 1 form, which is update and export submit button. The form is sent to templates/misc for process. Below is my code in codeigniter
1) View:

Code:
<?php
$attributes1 = array('name' => 'updateform');
echo form_open("?".$path.'misc',$attributes1);
?>
<span id="spec-header">&nbsp;Resource : &lt;?php echo $put_in;?&gt;&nbsp;</span><br />
    &lt;textarea name="tmpl_content" cols="100" rows="40"&gt;
        &lt;?php
            echo $file_details['file'][$look_up];
        ?&gt;
    &lt;/textarea&gt;
    <br />
    &lt;input type="hidden" name="templatename" value="&lt;?php echo $templatename;?&gt;" /&gt;
    &lt;input type="hidden" name="templatefileid" value="&lt;?php echo $tmpl_fileid; ?&gt;" /&gt;
    &lt;input type="hidden" id="templateid" name="templateid" value="&lt;?php echo $templateid ;?&gt;" /&gt;
    &lt;input type="submit" name="updatetemplate" value="Update" class="submit0" /&gt;
    &lt;input type="submit" name="exporttemplate" value="Export Template" class="submit1" /&gt;
&lt;/form&gt;

2) Controller
Code:
function misc(){
            
$templateid = trim($_POST['templateid']);
            
if ($_POST['updatetemplate']){
    $this->Templates_Model->update_template();
    redirect($this->path."view/".$templateid);
    exit;    
}
if ($_POST['exporttemplate']){
    //echo "here";
    $this->export_template();    
}    
}
But, once I have 2 submit button and either one button I submit, it will give me error say undefined index updatetemplate(if i submit exporttemplate). What's wrong with the code? Can't have more than 1 submit button at one form? Thanks.


  Use AJAX to validate a field
Posted by: El Forum - 09-05-2007, 12:13 AM - No Replies

[eluser]xcristi[/eluser]
Hello guys,

So, I know little about AJAX, but I need to implement such thing in a CI application. I just need from some directions, because I'm a little confuse here...

I have a form (view) with a input text field, let's say 'name' and a DB with a table that contains field 'names'. What I want to do is to verify the value entered for name in table and display a message 'No duplicate' or 'Duplicate name' (or something like that).

I load the library ajax but I haven't an idea what to put into view and what into controller. Maybe you could show me some direction to follow.

Thanks.


  Active Record: COUNT WHERE?
Posted by: El Forum - 09-04-2007, 10:36 PM - No Replies

[eluser]BravoAlpha[/eluser]
Does the Active Record class have a way to COUNT that supports a WHERE clause?

The current MySQL driver uses this:

Code:
function count_all($table = '')
    {
        if ($table == '')
            return '0';
    
        $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`");
        
        if ($query->num_rows() == 0)
            return '0';

        $row = $query->row();
        return $row->numrows;
    }


  Preventing direct access to images... or something...?
Posted by: El Forum - 09-04-2007, 09:05 PM - No Replies

[eluser]crikey[/eluser]
Hi all

I'm in the planning (pencil and paper) stage of my application, so sorry about the vagueness of my question and lack of code samples.

My app will allow users to upload items to a database. An "item" consists of data and an image associated with the item. Pretty basic. Two pieces of data that will be stored for an item is the user_id of the user adding the item, and a value that determines if the item is "public" or "private".

I would store the image as somepath/images/user_id/filename.jpg where filename is a random string of about 12 alphanumeric characters.

Registered and "guest" users of the application can search for items, and matching items will be listed in the results (only if "public"), including a thumbnail of each item's image, linking to the full-size image. Logged-in users can search and "public" items plus "private" items that match their user_id (using sessions I guess) will be included in the results.

My question is, because the HTML for the search results will include the image paths, what can I do to prevent someone who views the page source from typing lots of different combinations of filenames in the url and possibly getting an image associated with a "private" item?

Is there a programming or IA technique that is typical for such a thing?

Oh, I'm very new to PHP too, so if the solution is real obvious, don't be too hard on me!

Cheers


  Porting an application to CI
Posted by: El Forum - 09-04-2007, 08:56 PM - No Replies

[eluser]chic[/eluser]
Hi,
We have a legacy application in place and i was tasked to port it to a web application.
Being a minimalist myself, CI is the first choice for me, i know a little about PHP but the learning curve is not a problem. I would just like to ask some questions.

Is there a way to authenticate the user via postgresql authentication? (
$config['hostname'] = "localhost";
$config['username'] = "myusername";
)
and if this is possible, will it be able to handle multiple database users with different privileges at the same time? and can someone provide me with the code fragments? this has to be done since the database is already setup and running smoothly. there are about 100+ login roles with different restrictions/priviledges on the tables and about 800 users on the database.

thanks,
chic


  using mysql function in update function's config virable
Posted by: El Forum - 09-04-2007, 03:22 PM - No Replies

[eluser]杨帅[/eluser]
i use the following code to update a record in my database, but i want to use the mysql now() function in the config variable $data, the following syntaz output error, cuz php thought now() is a php function, and it cannot find it. if i surround quotes on now() as

Code:
'last_edit_time'=>'now()';
it also output error, cuz mysql thought "now()" is a string ,and it cannot be insert into a datetime collum in the database. anyone know how to solve this problem?
Code:
$data=array(
        'name'=>$name,
        'sex'=>$sex,
        'work_experience'=>$work_experience,
        'last_edit_time'=>now();
    );
            
        $username=$this->session->userdata('username');    
            
        $this->db->where('username', $username);
    $this->db->update('person', $data);


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

Username
  

Password
  





Latest Threads
Why PHP is still worth le...
by php_rocs
1 hour ago
my controller fails to fi...
by PaulC
4 hours ago
My Library cannot see ses...
by InsiteFX
9 hours ago
Any user guid or video o...
by InsiteFX
9 hours ago
update the framework to t...
by captain-sensible
Yesterday, 12:14 PM
CodeIgniter Shield 1.0.0 ...
by Ayatorvi
Yesterday, 06:06 AM
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
05-07-2025, 01:58 PM
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
Help parsing the log file...
by sophia2005
05-07-2025, 05:02 AM

Forum Statistics
» Members: 144,913
» Latest member: com7clubbuk
» Forum threads: 78,382
» Forum posts: 379,417

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB