Welcome Guest, Not a member yet? Register   Sign In
  DB_active_rec.php, function: select(), issue: cannot use MySQL IF function (not construct) + more.
Posted by: El Forum - 02-17-2008, 12:56 AM - Replies (2)

[eluser]MPress[/eluser]
You cannot use the MySQL IF function within the string argument for the select active-record function. This is because it tries to reconcile the values by exploding on a ','. Although, I somehow remember this not being an issue previously... Anyways, the IF function has the syntax of: IF({cond. is met}, {return this}, {otherwise this}).

Update:

As well, the new automatic backquote feature of AR functions fails on this kind of thing: FORMAT(something, 2) since we get FORMAT(`something`, `2`). 2 must be numeric and therefore cannot be enclosed in backquotes.

Here is a temporary workaround for the first issue. Simply escape special commas by doubling up (',,'). Follow $comma_fix.

Code:
function select($select = '*', $protect_identifiers = TRUE, $comma_fix = FALSE)
    {
        if (is_string($select))
        {
            if($comma_fix && strpos($select, ',,') !== FALSE){

                $select = str_replace(',,', '?~', $select);
            }

            $select = explode(',', $select);
        }

        foreach ($select as $val)
        {
            $val = trim($val);

            if($comma_fix && strpos($val, '?~') !== FALSE){

                $val = str_replace('?~', ',', $val);
            }

            if ($val != '*' && $protect_identifiers !== FALSE)
            {
                if (strpos($val, '.') !== FALSE)
                {
                    $val = $this->dbprefix.$val;
                }
                else
                {
                    $val = $this->_protect_identifiers($val);
                }
            }

            if ($val != '')
            {
                $this->ar_select[] = $val;
                if ($this->ar_caching === TRUE)
                {
                    $this->ar_cache_select[] = $val;
                }
            }
        }
        return $this;
    }


  CI + mootools + ajax (actually works)
Posted by: El Forum - 02-16-2008, 11:09 PM - No Replies

[eluser]mr_coffee[/eluser]
Yeah I saw some answers for this floating around. But none suited very SIMPLE needs. I found the following on some post on something or another but lack the patience to look it up again. The poster mention "extending" the input library with the following:

Code:
function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
    }

Which to me translated as "add this to the bottom of ci/libraries/input.php and re-upload".

Now in your controllers, you will now have the option to say if isAjax() do this... otherwise do something else. I'd say that something else is the default behavior which is to load the view for each item on the page... whereas if it was an Ajax call... instead of "viewing" navigation, the page layout, the title, etc... you're just "viewing" the one element on the page to be updated. I'll give you this example of actual code I am using:

Code:
function work() {
        if($this->input->isAjax()) {
            $this->load->view('work');            
        } else {
            $data['title'] = "Where I live and work";
            $this->load->view('title',$data);
            $this->load->view('scripts');
            $this->load->view('header',$data);
            $this->load->view('navigation');
            $this->load->view('work');
            $this->load->view('footer');
        }
    }

This works perfectly and as expected. I'll need to - however - add some javascript to update the <title> of the page and the text on the page that shows the title (fourth line in the else portion). Such a SIMPLE answer... reading all these "answers" about trying to re-invent the wheel was giving me a headache. Please repost this enough times that those posts will be trumped in the search engine by this easy working answer.

Contention: you CANNOT USE the safe_email() function on an ajax requested page. It utilizes the javascript d0cument.wr1t3 and that will break everything. Expect an "Operation Aborted" error thrown by IE and a white page that never finishes load in any other browser. Anyway, it will be messy. You could set evalScripts to false and kill the error, but you won't see your e-mail link either. There may be more things you can't use, but that's the one I noticed right away. NO DOCUMENT.WRITEs!


Now for my question: why is it that Opera doesn't display Ajax loaded content inside the specified div? This isn't a CI question, I was just hoping someone had a work-around for that, I'm coming up empty everywhere else. (ps... downloaded the DOM snapshot plugin for Opera: the code is perfect. Tells me the visual rendering should match up, but visually, my ajax requested pages are not displaying within the div I specified, even though by the DOM snapshot: they should be)

Now for my CI question: has anyone successfully written some sort of helper/library/class/ANYTHING that would handle an Ajax "history". Like along with my "$this->load->view('work');" I should have a line saying "$this->history->updateaddressbar('info/work'); $this->history->addclick();" or something like that so that basic back/forward/bookmark/reload functions would be restored. I was playing with something that worked "ok" in mootools, but it was kind of a hassle. I'm not really wanting to test what happens if I start adding hashes to the address bar either while CI is running. I don't expect positive results. I also already know the aforementioned history manager crashed and burned in Opera as well as the basic ajax calls. Strange... I was under the impression Opera allowed MORE things to work, not fewer. Whatever. If you're aware of a history addon thing, I'd like to know.

thanks much.


  Reading/Parsing Directories and Files
Posted by: El Forum - 02-16-2008, 09:27 PM - Replies (3)

[eluser]pgsjoe[/eluser]
Hate to rely on the message board, so I apologize. Here's the deal though. I have a directory called 'Photos' inside of photos are 'Category1', 'Category2', etc.

First thing I want to do is get an array of the directories inside 'Photos' so I can put those into a dropdown list. Second, I want to be able to get a list of files from inside the category chosen, to put inside their own dropdown list.

Idea being, the client would create directories and upload photos using an FTP client. Then, associate those files to Title, Alt tags and Dates using a CI form. The form would allow the person to enter previous info, then attach the file information (directory & filename) to it and upload it to the database.

The client is a photographer, and since they have access to an FTP I don't really see a form uploader as being entirely necessary. So, I thought this might be the easiest way. So any help with getting it to work, or suggestions on a better, hopefully not TOO complicate way would be awesome.

This is the first full client project I'm trying out CI on and am damn excited to be jumping in. Hence, sitting home on a Saturday night coding. Thanks in advance.


  Godaddy Error - No input file specified.
Posted by: El Forum - 02-16-2008, 09:07 PM - Replies (8)

[eluser]Unknown[/eluser]
Searched forums, tried everything, couldn't get anything to work. My host is godaddy. When I go to my site.com/index.php/category/ and it just says No input file specified. How do i fix this?

Thanks.


  Validating and prepping...
Posted by: El Forum - 02-16-2008, 08:45 PM - Replies (7)

[eluser]~Chris~[/eluser]
This may sound like a dumb question. Im going over the validation class.

Code:
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|md5";
$rules['passconf'] = "trim|required";
$rules['email'] = "trim|required|valid_email";

Just like the user guide says it would, when there is an error the password is still re-filled into the form with its new md5 hash, instead of the password the user typed in.

It says to prep the data after its done validating, instead of all together.

So, can someone give me an example of how I would prep it. For example? do i just run the $this->validation->run() function a second time to handle the data prepping?

your help is appreciated.


  default request by extending Router
Posted by: El Forum - 02-16-2008, 08:30 PM - Replies (6)

[eluser]zauber[/eluser]
Hi, here's a small contribution that some might find useful.

I'm working on a really simple and sweet CMS with CodeIgniter, which handles pages that basically just have content and slugs (a string that only contains alphanumerics and underscores)

when you visit

Code:
http:://www.mysite.com/pages/read/some_slug

then the task of Pages->read($slug) would be to show the content of the page with slug 'some_slug'.

now... I wanted to be able to enter:

Code:
http:://www.mysite.com/some_slug


and get the same effect. But I wanted to do it in a way that it wouldn't disturb any other routes. (Simply adding a $route[:any] = "pages/read", didn't work.

I solved it by extending the Router class, and allowing another special $route index.

Heres the Router extension:
Code:
class MY_Router extends CI_Router{
    function _validate_segments($s){
        if (count($s)==1 && !file_exists(APPPATH.'controllers/'.$s[0].EXT)){
            if (isset($this->routes['default_query'])){
                $segments = explode("/",$this->routes['default_query']);
                $segments[] = $s[0];
                $this->set_class($segments[0]);
                $this->set_method($segments[1]);
                return $segments;
            }
            show_404();
        }
        else return parent::_validate_segments($s);
    }
}

The special $route index is 'default_query' and it work so that if you put in:

Code:
$route['default_query'] = "mycontroller/amethod"

then any requests like:

Code:
http://mysite.com/writesomethinghere

will execute as: MyController->amethod('writesomethinghere');

My questions are:

1) Is there a more direct 'built-in' way of achieving this that I have overlooked?
2) Does this punch any holes in security or break functionality in some way I have yet to notice?
3) Is this the most efficient (computing-wise) way of adding this feature, without hacking the Router class directly? I tried to avoid as much repetition of code in the Router class as possible, and adding as little new code as possible myself, but I'm not sure how well I succeeded.


  File upload and image resize all in one
Posted by: El Forum - 02-16-2008, 07:51 PM - Replies (1)

[eluser]Unknown[/eluser]
I'd like to resize images as they are uploaded. I've got uploading working fine but how do I intercept the upload data and perform the image resize? I imagine I'd need to create a new function in my upload controller to handle resizes and then somehow call that controller from the upload action? Maybe? Is that the best way to approach it? If so, how do you call one function from another within a class?


  How CodeIgniter do the data parsing from array?
Posted by: El Forum - 02-16-2008, 12:39 PM - Replies (3)

[eluser]Unknown[/eluser]
Hi folks,

Would anyone tell me how CodeIgniter do this?
In the controller call any view and pass an array of data inside. And in the view file, we can access to the data element directly.

Like this:
$data['var1'] = 'value 1';
$this->load->view( 'view_hello', $data);

and in view_hello.php we can use $var1.

I only can do: $this->var1 but not $var1 directly.


Great thanks and regards,
H


  .htaccess redirect issues
Posted by: El Forum - 02-16-2008, 12:34 PM - Replies (4)

[eluser]exodus7[/eluser]
I seem to be having some problems with my .htaccess file when I add a redirect to it.

This is what I had originally:

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
AddHandler php5-script .php
This is what I had after:
Code:
RewriteEngine On
RewriteRule ^index\.php\?id\=1$ http://www.mydomain.net/index.php/home/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
AddHandler php5-script .php
I've also tried:
Code:
RewriteEngine On
RedirectMatch permanent ^/index\.php\?id=80$ http://www.mydomain.net/services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
AddHandler php5-script .php
And tried this:
Code:
RewriteEngine On
RedirectMatch 301 ^/index\.php\?id=80$ http://www.mydomain.net/services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
AddHandler php5-script .php

But still no luck. What did I do wrong?


  .htaccess wow's
Posted by: El Forum - 02-16-2008, 12:05 PM - Replies (2)

[eluser]OES[/eluser]
Hi Chaps.

I am a complete newbie to ci so please be gentle.

I have just installed the basic package and all is working well as it should be.

But as with many posts n these forums I cannot remove the index.php file without getting 404 errors.

I am trying ci on a subdmain running apache2, php5 on the Ubunto distro.

I have removed the index.php from the congfig ie,

Code:
$config['index_page'] = "";

I have tried alot of different variations of the mod_rewrite. ie.

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

I cannot get any of these to work.

I know mod_rewrite is working on other domains.

I hope someone can advise before I have no hair left.

thanks in advance.


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

Username
  

Password
  





Latest Threads
Is it possible to go back...
by Bosborne
38 minutes ago
VIRUS reported after Chro...
by InsiteFX
4 hours ago
Codeigniter4 version 4.5....
by kenjis
11 hours ago
SQL server connection not...
by kenjis
11 hours ago
Problem with session hand...
by kenjis
11 hours ago
Cannot access protected p...
by xsPurX
Yesterday, 02:10 PM
Update to v4.5.1, same us...
by xsPurX
Yesterday, 08:31 AM
How to use Codeigniter wi...
by kenjis
Yesterday, 05:06 AM
CVE-2022-40834 SQL Inject...
by kenjis
Yesterday, 03:44 AM
Retaining search variable...
by pchriley
Yesterday, 03:15 AM

Forum Statistics
» Members: 85,444
» Latest member: fb777orgph
» Forum threads: 77,581
» Forum posts: 376,009

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB