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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 12,135
» Latest member: wlmxqh123
» Forum threads: 68,432
» Forum posts: 426,809

Full Statistics

Latest Threads
Output is filled with war...
Forum: General Help
38 minutes ago
» Replies: 4   » Views: 56
nodejs tips and tricks
Forum: Lounge
2 hours ago
» Replies: 31   » Views: 710
Form validation: error me...
Forum: Libraries & Helpers
4 hours ago
» Replies: 2   » Views: 49
Soft Delete VS hard Delet...
Forum: Best Practices
7 hours ago
» Replies: 2   » Views: 171
Redirect vs load view
Forum: Model-View-Controller
9 hours ago
» Replies: 8   » Views: 188
How to avoid spam emails?
Forum: Lounge
10 hours ago
» Replies: 1   » Views: 48
FrameworkException::forEm...
Forum: CodeIgniter 4 Support
Yesterday, 11:13 AM
» Replies: 2   » Views: 111
Import certain cells of M...
Forum: General Help
Yesterday, 10:47 AM
» Replies: 2   » Views: 70
How to start session glob...
Forum: CodeIgniter 4 Support
Yesterday, 10:21 AM
» Replies: 10   » Views: 130
to use / or to use \ ?
Forum: General Help
Yesterday, 05:55 AM
» Replies: 4   » Views: 137

 
  Yats and scaffolding
Posted by: El Forum - 09-16-2007, 02:03 PM - Forum: Archived Libraries & Helpers - Replies (3)

[eluser]Jose Dueñas[/eluser]
Hi folks!
I'm having some problems with scaffolding and yats.

I have my controller like that:

Code:
<?php

class Inmo extends Controller
{
    function Inmo()
    {
        parent::Controller();
        $this->load->scaffolding('properties_sale');
    }    
    
    function index()
    {
        // Set the template valiables
        $data['mensaje'] = "A Message";

        // Build the thing
        $this->layout->buildPage('inmo/home', $data);
        
    }
}

?>

If I go to: http://localhost:8888/inmo/index.php/inmo/secret_word I can see the scaffolding page, but if I click to Add New Record, a 404 page is shown.

Is there any problem working with scaffolding and yats together?

Thanks!


  Auto Install scripts - my ideas & code
Posted by: El Forum - 09-16-2007, 07:53 AM - Forum: Archived Development & Programming - No Replies

[eluser]phpMaster[/eluser]
hi!
Auto Install scripts - my ideas & code

A usual way to test if app is installed, is to check 'config.php' exists or is not empty.
I have another approach, that makes such tests are not needed.
This will spare at least one IF execution, each time app is called.

My default 'config.php' have this:

Code:
<?php

session_start();
$_SESSION['install']=true;
header('location: install.php');
exit();

?>

After Auto Install parameters has been submitted,
a new 'config.php' is written with the values.

I prefer to use auto install step by step. With only few fields in each.
In this code I am working on, there are 3 steps.
I use switch - case and valid values from each step are stored $_SESSION.

'install.php'
Code:
<?php

session_start();
if(!isset($_SESSION['install']))
    exit('no');

//install
$step = (isset($_POST['step'])) ?  $_POST['step'] : 0;

switch( $step ):
case 1 :
    $sitename=trim($_POST['sitename']);
    include('install.forms.inc.php');
    $len=strlen($sitename);
    if($len<4){
        $out=$form1.$ms1.'Site name too short'.$ms2;
        break;
    }
    $_SESSION['sitename']=$sitename;
    $out = $form2;
    break;
case 2 :
    $forum1=trim($_POST['forum1']);
    $forum2=trim($_POST['forum2']);
    $forum3=trim($_POST['forum3']);
    include('install.forms.inc.php');
    $len=strlen($forum1);
    if($len<4){
        $out=$form2.$ms1.'Forum 1 name too short'.$ms2;
        break;
    }
    $len=strlen($forum2);
    if($len!=0 && $len<4){
        $out=$form2.$ms1.'Forum name too short'.$ms2;
        break;
    }
    $len=strlen($forum3);
    if($len!=0 && $len<4){
        $out=$form2.$ms1.'Forum name too short'.$ms2;
        break;
    }
    $_SESSION['forums']=array($forum1,$forum2,$forum3);
    $out = $form3;
    break;
case 3 :
    $adminuser=trim($_POST['adminuser']);
    $adminpass=trim($_POST['adminpass']);
    include('install.forms.inc.php');
    $len=strlen($adminuser);
    if($len<6){
        $out=$form3.$ms1.'Admin username too short'.$ms2;
        break;
    }
    $len=strlen($adminpass);
    if($len<6){
        $out=$form3.$ms1.'Admin password too short'.$ms2;
        break;
    }
    $_SESSION['adminuser']=$adminuser;
    $_SESSION['adminpass']=$adminpass;
    include('install.writeconfig.inc.php');
    define("DBINSTALL",true);
    include('install.db.inc.php');
    $out = '<h2>Thank you.<br>You can now use your forum.</h2>';
    $out.= 'Admin User: <b>'.$adminuser.'</b><br>';
    $out.= 'Admin Pass: <b>'.$adminpass.'</b><br>';
break;    
default:
    include('install.forms.inc.php');
    $out =$form1;
endswitch;

echo $header.$out.$footer;

?&gt;
There is only one (1) 'echo' in total installing process!
This is when I know, I have managed to separate php-code/html-output well.


Regards, phpMaster


  validation problems
Posted by: El Forum - 09-16-2007, 07:09 AM - Forum: Archived Development & Programming - Replies (10)

[eluser]feri_soft[/eluser]
I have two validation issues. First one i have a login system and i wanted to create my callback for the validation to see if the following data is correct and the users logs in

So here is something:

Code:
function login()
    {
        $this->validation->set_message('check_login', 'sdfdfsdf');
        $rules['username'] = "trim|required|callback_check_login|xss_clean";
        $rules['password'] = "trim|required|xss_clean";
        $rules['remember'] = "numeric";
        $this->validation->set_rules($rules);
        
        $fields['username'] = 'asda';
        $fields['password'] = 'sdasd';
        $fields['remember'] = 'asdasd';
        $this->validation->set_fields($fields);
        
        if ($this->validation->run() == false)
        {
            $this->load->view('login');
        }else{
            $this->load->view('profile');
        }
    }

And i have created a simple callback to check the login:
Code:
function _check_login($username, $password, $remember){
        if($this->user_model->login($username, $password, $remember)){
            return true;
        }else{
            return false;
        }
    }
Obviously this doesnt work as the validation requires only one parameter to work. I could create something else like checking the login in the else clause and if error occurs display the login form with an array data containing something like: '1' => 'No such user', '2' => 'Wrong pass' etc...but i thing this is kind of a double work first create erros array in validation and then create 2nd errors array for login check. Makes no sense. Isnt there a way working with the Ci itself with no other modifications to make my idea working and use callback with multiple attributes. Like the matches and min_lenght / max_lenght funcs.

And i have another very simillar problem tried to create telephone check to see if a user has entered a valid phone or valid GSM and if none of the two is entered display error. So i wrote something like:

Code:
function _phoneorgsm(){
        if(!empty($_POST['phone']) && is_numeric($_POST['phone'])){
            return true;
        }elseif(!empty($_POST['gsm']) && is_numeric($_POST['gsm'])){
            return true;
        }else{
            return false;
        }
    }


but for some reasons it doesnt work just displays me the page with all other errors and not this one. I suppose the same will happen if i try this on the login so i didnt. Here is the function:
Code:
$this->validation->set_message('phoneorgsm', 'asdasdasdasd');
    $rules['phone'] = "trim|callback_phoneorgsm";
        $rules['gsm'] = "trim|callback_phoneorgsm";
etc....

Any ideas i need something very very urgently because i am on a hurry with this one. Thanks a lot !


  Reloading view form with data which was passed by controller view form, not form validation fields
Posted by: El Forum - 09-16-2007, 06:07 AM - Forum: Archived Development & Programming - Replies (3)

[eluser]OneCorea[/eluser]
Suppose this!...
board controller(board/bRead) loads a read view transferring with data[] fields..
and in the read view..there's a form section in the middle of read view file,
When the form submitted, it's called the controller&method;(board/commentPost) and reloading the same view file('read' view file)


Well, here's my problem!!!..

when the 'read' view file reloaded after the form submitted..
the data[] fields is disappeared because I didn't load the data[] field inside commentPost function...

You may ask "Why don't you define every data[] fields in the function..??",
but there's lots of data[] field to define..

So,
Is there any method for 'commentPost() function' to receive every data[] field in the read view file loaded by the controller(board/bRead)?


<controllers/board.php>

Code:
class Board extends Controller{
...
...
   function bRead(){
   ....
   $data['aaa'] = 'this is aaaa data in read view';
   $data['bbb'] = 'bbb';
   ==> There's lots of $data[] fields..

   $this->load->view('read', $data);
   }

   function commentPost(){
    ...
    if($this->validation->run()){
       //==> inserting database..

       $this->load->view('read');
    }
    else{
       error msg;;;
       $this->load->view('read');
    }

   }

}

View/read.php
Code:
&lt;html&gt;&lt;body&gt;
&lt;?=$aaa?&gt;
..blah blah
&lt;?=$bbb?&gt;
...blah blah
there are lots of data field from controller
...
&lt;?=form_open('board/commentPost/$code/$no')?&gt;
   &lt;input type=text name='writer&gt;
   &lt;textarea name=comment&gt;&lt;/textarea&gt;
   &lt;input type=submit value='Submit'&gt;
&lt;/form
</body&gt;&lt;/html&gt;


  Application design
Posted by: El Forum - 09-15-2007, 07:57 PM - Forum: Archived Development & Programming - Replies (1)

[eluser]Unknown[/eluser]
I want to use CodeIgniter for future web sites.
My web sites tend to have a lot of common functionality; the ability to add new pages, edit old ones, post news, use a contact form etc.
Occasionally I want to add new features. Maybe a link database or a poll system.

That's why I'd like a module-based approach. And I want all administrative features for controlling the different modules in one place (eg. /admin).

Before discovering CodeIgniter, I was in the process of writing my own little "CMS". I hadn't heard the term "MVC" when I started, but it did something like this:

(Simplified a bit, but illustrates the idea)

Code:
// Syntax:
// $template->assign($part_of_page, $content);
//  ... where $content usually is a call to $module->execute which returns module output

$main_module = $_GET['module'];

// Assign content. First the requested module, and then some extra stuff
$template->assign('content', $module->execute($main_module, 'index');
$template->assign('content', $module->execute('polls', 'showpoll', 45);

// And maybe a block?
$template->assign('right_blocks', $module->execute('articles', 'show_article', 3);

// These assignments could even be defined in a database so that the administrator could control every part of the page rendering.
So every module is like a controller. That's why I initially wondered if CodeIgniter could instantiate multiple controllers.



There are a couple of things I want to ask.

1. Would the module be the controller? Or the models/libraries? Or a combination?
2. What if I want to have a poll in the sidebar of one of my pages? Ie. I have a showpoll() method in my poll controller, and I want that exact output on the side of every page.
3. Comments on my approach above?
4. What about an admin panel? Every controller has an admin version (which is located in controllers/admin?

Actually, I'm not exactly sure what I want to ask. But any input would be great Smile


  Executing a controller based on criteria other than URL?
Posted by: El Forum - 09-15-2007, 07:36 PM - Forum: Archived General Discussion - Replies (5)

[eluser]Unknown[/eluser]
For each visit to my app, regardless of the requested page, I need to execute some common code. It is quite possible that this code will determine that a controller other than the controller dictated by the route should be executed.

Unfortunately, after digging through the core code, I've found no way of doing the above. I would have thought that there would be some kind of hook that lets you change the controller on-the-fly before it is actually executed, but it doesn't look like this is the case. Am I missing something obvious?

I'd really prefer to not have to do a redirect for various reasons.


  Categories and Sub Categories
Posted by: El Forum - 09-15-2007, 06:30 PM - Forum: Archived Development & Programming - Replies (12)

[eluser]CI pedro[/eluser]
Hello all,

I have looked at CodeIgniter before and I finally got back to it and decided to try to use it for a site I am building.

I am new to using CodeIgniter and not all that experienced with PHP (read as haven't done any production code in PHP).

So, the site I am building is a local classifieds site and the problem I am having is figuring out how to go about listing out Categories with Sub Categories listed under the Categories.

I did see something earlier that said it would be useful in such a situation but cannot for the life of me find it again. Besides even if I did find it again I wouldn't know how to implement it in CI.

My Table is as follows:

Category
------------------
id
parentid
category
active

obviously self referential

I have a Category Model that has methods to get the categories and a method to get the subcategories by categoryid

could someone please point me in the right direction?

Any help will be greatly appreciated.

If you need more info please let me know

Thank you


  Date in text field
Posted by: El Forum - 09-15-2007, 04:41 PM - Forum: Archived General Discussion - Replies (3)

[eluser]Kemik[/eluser]
Hello,

I know this is a weird question but how do you guys/girls get dates from the user? I'm trying a text field and then storing it in the database (DATE format) however the date isn't saved, just the rest of the query. I've checked all the names to make sure its not a silly mistake but they're all correct.

Fancy taking a look please?

Code:
&lt;?php

$this->validation->set_error_delimiters('<p class="important" style="width: 300px;">', '</p>');
        
$rules['datetime']        = "trim|required|callback_datetime|xss_clean";
$rules['occurs']        = "trim|required|callback_occurs|xss_clean";
$rules['event']         = "trim|required|xss_clean|strip_tags";
        
$this->validation->set_rules($rules);
        
$fields['datetime']        = 'Date';
$fields['occurs']        = 'Occurs';
$fields['event']        = 'Event';
    
$this->validation->set_fields($fields);
        
if ($this->validation->run() == TRUE) {        
            
if ($this->input->post('occurs') == 'one-time') {
            
  $insert = array(
    'date' => $this->input->post('datetime') ,
    'details' => $this->input->post('event')
  );
    
  $this->db->insert('one_events', $insert);
                
  $data['message'] = TRUE;
}
}
?&gt;

The date is validated for dd-mm-yyyy


  Date validation?
Posted by: El Forum - 09-15-2007, 12:21 PM - Forum: Archived Development & Programming - Replies (30)

[eluser]Mart[/eluser]
Hi

I was expecting to be able to use the CI Validation class to to validate dates on my forms. The user guide doesn't show any examples.

Does the validation class class support date checking?

How would I go about it otherwise? (Callbacks? I could use one of those I guess)

Cheers


  Full example for Xajax 0.5.3 with Nusoap 1.94 for CI 1.5.4
Posted by: El Forum - 09-15-2007, 11:25 AM - Forum: Archived Development & Programming - Replies (10)

[eluser]Leonardo Radoiu[/eluser]
This full working example is the conclusion on the following topics:

http://ellislab.com/forums/viewthread/59808/
http://ellislab.com/forums/viewthread/59710/

First, you need to have the following pre-requisites: a web server of your choice (IIS or Apache), PHP >= version 5.0, CI 1.5.4 installed, Xajax 0.5.3 library installed in CI, Nusoap 1.94 installed in CI, jquery 1.1.4 library, a Mysql server >= version 5.0 (the example requires a mysql server with stored procedures support), Firefox with Firebug plugin (for debugging).

Step 1. Create a table named "members" with the following table schema:

Code:
-- Table "members" DDL

CREATE TABLE `members` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) CHARACTER SET latin1 NOT NULL,
  `lastname` varchar(255) CHARACTER SET latin1 NOT NULL,
  `birthday` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 CHECKSUM=1

Fill the table with some data:
Code:
id    firstname    lastname    birthday
--------------------------------------------------
1    John        Smith        1978-05-03
2    John        Doe        1980-10-10
3    Jane        Doe        1975-02-07
4    Juan        Perez        1950-09-30
5    Jean        Dupont        1990-08-24
6    Mario        Rossi        1943-12-04
7    Jan        Novak        1963-11-16
8    Joe        Borg        1986-05-01
9    Paul        Martin        1965-04-13
10    Jaan        Tamm        1971-05-19
11    Ion        Popescu        1976-01-21
--------------------------------------------------

Step 2. Create 3 stored procedures that will be required for data selection:
Code:
CREATE PROCEDURE `MYSQL_select_members`(IN _start INT, IN _limit INT, IN _sortField VARCHAR(20), IN _sortOrder VARCHAR(4))
BEGIN
    DECLARE _SQLOrder VARCHAR(255);
    DECLARE _SQLLimit VARCHAR(255);

    IF (_start >= 0 AND _limit > 0) THEN
        SET _SQLLimit = CONCAT(" LIMIT ", _start, ", ", _limit);
    ELSE
        SET _SQLLimit = "";
    END IF;

    IF (_sortField <> '' AND _sortOrder <> '') THEN
        SET _SQLOrder = CONCAT(" ORDER BY ", _sortField, " ", _sortOrder);
    ELSE
        SET _SQLOrder = "";
    END IF;

    SET @SQL = CONCAT("SELECT * FROM `members` ", _SQLOrder, _SQLLimit);
    PREPARE _SQL FROM @SQL;
    EXECUTE _SQL;
    DEALLOCATE PREPARE _SQL;
END
Code:
CREATE PROCEDURE `MYSQL_select_member_info`(IN _id INT)
BEGIN
    SELECT * FROM `members` WHERE id = _id;
END
Code:
CREATE PROCEDURE `MYSQL_count_members`()
BEGIN
    SELECT COUNT(*) AS `count` FROM `members`;
END



  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.