More example in raxan framework

Tell us what you would like to see added to framework

More example in raxan framework

Postby noviandi_pakuan » Thu Nov 04, 2010 11:12 am

share more an example for raxan framework.
Last edited by noviandi_pakuan on Thu Nov 04, 2010 11:29 am, edited 1 time in total.
noviandi_pakuan
 
Posts: 43
Joined: Mon Nov 01, 2010 2:50 am

Re: MORE EXAMPLE IN RAXAN FRAMEWORK

Postby noviandi_pakuan » Thu Nov 04, 2010 11:24 am

needed help,

i download login-demo yesterday and try to implement it with a few modification but it's not work, please give me your suggest and fix if i'am wrong ...
i use raxan for developer 201006

here a line of code ...

Code: Select all
require_once "../raxandev10/raxan/pdi/autostart.php";

class HomePage extends RaxanWebPage {
   
   protected $db;
   protected function _authorize() {
        $isLogin = Raxan::data('MySession','isLogin');
        if ($isLogin){
          $this['#form-right']->html('<div class="success">You already logged in.</div>');
      }
        return true;
    }
    protected function _init() {
        $this->source('view/index.html');
      $this->db = $this->Raxan->connect('mysql:host=localhost; dbname=appol','root','',true);
      if (!$this->db){
            $this->halt('<h2>Unable to connect to the MySQL Database.</h2>');
        }
    }
   
    protected function _load() {
        $examples = Raxan::importCSV('examples.csv');
        $this->list->bind($examples);
    }
   
   protected function login($e) {    // event callback
        $msg = array();
        $data = $this->sanitizePostBack();
      $usr = $data->value('username');
        $pwd = $data->value('password');
      $cmp = $data->value('company');
        // validate user input
      if (!$cmp) $msg[] ='Please enter a valid Company name.';
        if (!$usr) $msg[] ='Please enter your user name.';
        if (!$pwd) $msg[] ='Please enter a valid password.';
      
      $this['#form-right']->html('Record sucessfully removed','bounce','notice');
       
      $data = $this->db->table("dbuser userid,username,password,dbname","username=?","'".$usr."'");
        if (strtolower($data[2])==strtolower($pwd) && strtolower($data[3])==strtolower($cmp)){
            Raxan::data('MySession','isLogin',true);
            $this['#form-right']->html('<div class="success">Login was successfull.</div>');
         }else{
            $msg = '<strong>'.implode('<br />',$msg).'</strong>';
               $this['#form-right']->html($msg)->show();
         }
      
   }

    protected function logout($e) {
        Raxan::removeData('MySession','isLogin');
        $this->redirectTo('index.php');
    }
}

and here a piece of html ...
Code: Select all
<form id="form1" name="form1" action="" method="post">
<H2>Login Form</H2>
   <div id="form-left">
             <legend>Login</legend>
                   <input type="text" name="company" id="company" value="" class="tip-form" title="Required" onfocus="if(this.value=='Company')this.value='';" onblur="if(this.value=='')this.value='Company';" value="Company" class="tip-form"/>
                  <input type="text" name="username" id="username" value="" class="tip-form" title="Required" onfocus="if(this.value=='User Name')this.value='';" onblur="if(this.value=='')this.value='User Name';" value="User Name" class="tip-form"/>
            <input type="text" name="password" id="password" value="" class="tip-form" title="Required" onfocus="if(this.value=='Password')this.value='';" onblur="if(this.value=='')this.value='Password';" value="Password" class="tip-form"/>
        </div>
   <div id="form-right">test</div>
   <input type="submit" value="Login" xt-bind="click,login"/>
</form>
noviandi_pakuan
 
Posts: 43
Joined: Mon Nov 01, 2010 2:50 am

Re: MORE EXAMPLE IN RAXAN FRAMEWORK

Postby raymond » Fri Nov 05, 2010 12:28 am

noviandi_pakuan wrote:needed help,
i download login-demo yesterday and try to implement it with a few modification but it's not work, please give me your suggest and fix if i'am wrong ...
i use raxan for developer 201006


Hi Noviandi,

I've modified your script so that it's now working with a test database that I've created. There were a few errors with the way in which you were using the table() method. See the updated code below.

Remember to change the database connection information.

Code: Select all
<?php

require_once "raxan-devsnap/pdi/autostart.php";

class HomePage extends RaxanWebPage {

    protected $db;

    protected function _init() {
        $this->source('views/index.html');
        $this->loadCSS('master');
        $this->preserveFormContent = true;
        try {
            $this->db = $this->Raxan->connect('mysql:host=localhost; dbname=test', 'user', 'password', true);
        } catch(Exception $e){
            $this->halt('<h2>Unable to connect to the MySQL Database.</h2>');
        }
    }

    protected function _authorize() {
        $isLogin = Raxan::data('MySession', 'isLogin');
        if ($isLogin) {
            $this['#form-right']->html('<div class="box success">You already logged in.</div>');
        }
        return true;
    }

    protected function login($e) {    // event callback
        $msg = array();
        $data = $this->sanitizePostBack();
        $usr = $data->value('username');
        $pwd = $data->value('password');
        $cmp = $data->value('company');

        // validate user input
        if (!$cmp)
            $msg[] = 'Please enter a valid Company name.';
        if (!$usr)
            $msg[] = 'Please enter your user name.';
        if (!$pwd)
            $msg[] = 'Please enter a valid password.';

        // display validation message
        if ($msg) {
            $msg = '<strong>' . implode('<br />', $msg) . '</strong>';
            $this['#form-right']->html('<div class="box error">'.$msg.'</div>')->show();
            return ;
        }

        // search database for user name
        try {
            $data = $this->db->table("users userid,username,password,company", "username=?", $usr);
        } catch(Exception $e) {
            $this['#form-right']->html('<div class="error">Error while logging in. Please try again.</div>');
            return;
        }
       
        if ($data && strtolower($data[0]['password']) == strtolower($pwd) && strtolower($data[0]['company']) == strtolower($cmp)) {
            // login ok
            Raxan::data('MySession', 'isLogin', true);
            $this['#form-right']->html('<div class="box success">Login was successful.</div>');
        }
        else {
            // login failed
            $this['#form-right']->html('<div class="box error">Login was unsuccessful.</div>');
        }
    }

    protected function logout($e) {
        Raxan::removeData('MySession', 'isLogin');
        $this->redirectTo('index.php');
    }

}
?>


Here's the html for the view:

Code: Select all
<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Login Test</title>
    </head>

    <body>
        <form id="form1" name="form1" action="" method="post" >
            <div id="form-left" class="container c20">
                <H2>Login Form</H2>
                <legend>Login</legend>
                <input type="text" name="company" id="company" value="" class="tip-form" title="Required" onfocus="if(this.value=='Company')this.value='';" onblur="if(this.value=='')this.value='Company';" value="Company" class="tip-form"/>
                <input type="text" name="username" id="username" value="" class="tip-form" title="Required" onfocus="if(this.value=='User Name')this.value='';" onblur="if(this.value=='')this.value='User Name';" value="User Name" class="tip-form"/>
                <input type="text" name="password" id="password" value="" class="tip-form" title="Required" onfocus="if(this.value=='Password')this.value='';" onblur="if(this.value=='')this.value='Password';" value="Password" class="tip-form"/>
                <div id="form-right" class="tpm bmm">test</div>
                <input type="submit" value="Login" xt-bind="click,login"/>
            </div>
        </form>
    </body>

</html>

raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: More example in raxan framework

Postby noviandi_pakuan » Fri Nov 05, 2010 2:10 pm

thanks a lot for the reply and your generous ....

i already try like you wrote but it seem not work, there is a few problem :
1. when firts i load the page, the "form-right" has a text like
you already login
is there anything wrong with authentication code ??
2. when using $this->$db=Raxan::connect has result can't connect to mysql but when i use
Code: Select all
            $dns = 'mysql:host=localhost;dbname=appol';
            $db = Raxan::connect($dns,'root','',true);

it work cause it can load the index.html ???
3. when i click submit, it's not success bind to function login, i try to put halt to see if it work but it not show at all...
4. when i try other sample like notes.php which include in developer20100614 it not work with error like this ..
Uncaught Error: Page element 'noteList' or property not found Line 323 in E:\EasyPHP\www\raxandev10asli\raxan\pdi\shared\raxan.webpage.php
#0 E:\EasyPHP\www\raxandev10asli\examples\notes.php(29): RaxanWebPage->__get('noteList')
#1 E:\EasyPHP\www\raxandev10asli\raxan\pdi\shared\raxan.webpage.php(254): NotesPage->_indexView()
#2 E:\EasyPHP\www\raxandev10asli\raxan\pdi\autostart.php(68): RaxanWebPage->__construct('')
#3 E:\EasyPHP\www\raxandev10asli\raxan\pdi\autostart.php(55): raxan_auto_create('NotesPage', '')
#4 [internal function]: raxan_auto_startup('E:\EasyPHP\www\...')
#5 {main}

5. could you tell us the newbie, a newest raxan framework that can be use with php-exampes and develover examples, cause when i use raxan 10 beta 3 and put the developer example it alway's error like Question no.4

Thank for your help !!!
noviandi_pakuan
 
Posts: 43
Joined: Mon Nov 01, 2010 2:50 am

Re: More example in raxan framework

Postby raymond » Fri Nov 05, 2010 7:17 pm

noviandi_pakuan wrote:1. when firts i load the page, the "form-right" has a text like "you already login" is there anything wrong with authentication code ??


Here's an update to my previous post. I was using an old syntax for Raxan::data() method. This version requires the current dev-snapshot. It will not work with beta 3

Code: Select all
<?php

require_once "raxan/pdi/autostart.php";

class HomePage extends RaxanWebPage {

    protected $db;

    protected function _init() {
        $this->source('views/index.html');
        $this->loadCSS('master');
        $this->preserveFormContent = true;
        try {
            $user = 'root';
            $password = '';
            $dsn = 'mysql:host=localhost; dbname=appol';
            $this->db = Raxan::connect($dsn, $user, $password, true);
        } catch(Exception $e){
            $this->halt('<h2>Unable to connect to the MySQL Database.</h2>');
        }
    }

    protected function _authorize() {
        $isLogin = Raxan::data('isLogin');
        if ($isLogin) {
            $this['#form-right']->html('<div class="box success">You already logged in.</div>');
        }
        return true;
    }

    protected function login($e) {    // event callback

        $msg = array();
        $usr = $this->post->value('username');
        $pwd = $this->post->value('password');
        $cmp = $this->post->value('company');

        // validate user input
        if (!$cmp)
            $msg[] = 'Please enter a valid Company name.';
        if (!$usr)
            $msg[] = 'Please enter your user name.';
        if (!$pwd)
            $msg[] = 'Please enter a valid password.';

        // display validation message
        if ($msg) {
            $msg = '<strong>' . implode('<br />', $msg) . '</strong>';
            $this['#form-right']->html('<div class="box error">'.$msg.'</div>')->show();
            return ;
        }

        // search database for user name
        try {
            $data = $this->db->table("users userid,username,password,company", "username=?", $usr);
        } catch(Exception $e) {
            $this['#form-right']->html('<div class="error">Error while logging in. Please try again.</div>');
            return;
        }
       
        if ($data && strtolower($data[0]['password']) == strtolower($pwd) && strtolower($data[0]['company']) == strtolower($cmp)) {
            // login ok
            Raxan::data('isLogin', true);
            $this['#form-right']->html('<div class="box success">Login was successful.</div>');
        }
        else {
            // login failed
            $this['#form-right']->html('<div class="box error">Login was unsuccessful.</div>');
        }
    }

    protected function logout($e) {
        Raxan::removeData('isLogin');
        $this->redirectTo('index.php');
    }

}
?>



3. when i click submit, it's not success bind to function login, i try to put halt to see if it work but it not show at all...


Try clearing your browser cache and cookies and reload the login page.

4. when i try other sample like notes.php which include in developer20100614 it not work with error like this ..
Uncaught Error: Page element 'noteList' or property not found Line 323 in E:\EasyPHP\www\raxandev10asli\raxan\pdi\shared\raxan.webpage.php
#0 E:\EasyPHP\www\raxandev10asli\examples\notes.php(29): RaxanWebPage->__get('noteList')
#1 E:\EasyPHP\www\raxandev10asli\raxan\pdi\shared\raxan.webpage.php(254): NotesPage->_indexView()
#2 E:\EasyPHP\www\raxandev10asli\raxan\pdi\autostart.php(68): RaxanWebPage->__construct('')
#3 E:\EasyPHP\www\raxandev10asli\raxan\pdi\autostart.php(55): raxan_auto_create('NotesPage', '')
#4 [internal function]: raxan_auto_startup('E:\EasyPHP\www\...')
#5 {main}


It works for me. Check the file views/notes.index.php for the an element with the id "noteList"

5. could you tell us the newbie, a newest raxan framework that can be use with php-exampes and develover examples, cause when i use raxan 10 beta 3 and put the developer example it alway's error like Question no.4


I'm working on a new release at the moment. It should have been released last week but it's currently behind schedule. A lot has changed since Beta 3 but we have documented the changes so that easier to work with.

Thanks for taking the timeout to test and give feedback to help make improve the framework .

Let me know if the code changes worked for you.

__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: More example in raxan framework

Postby noviandi_pakuan » Sat Nov 06, 2010 3:08 pm

thank for your time to answer my question, but it still can't work yet,
i already try over and over, and also check char by char to ensure if i wrong in type.

i also try to clear cache and cookies but it still not work at all.

and for developer example when use in beta 3 it just output
Render Time: 0.00070595741271973

without any picture at all ...


i attach code below, the difference is only at require once method ...

thank's for your kindness
Attachments
code.rar
(1.53 KiB) Downloaded 1372 times
noviandi_pakuan
 
Posts: 43
Joined: Mon Nov 01, 2010 2:50 am

Re: More example in raxan framework

Postby raymond » Mon Nov 08, 2010 6:25 am

Hi,

It appears as if the attached file code.rar is damaged. Can you please upload a new copy of the file?

Btw, you might want to check out the new developer snapshot and test it with your login script. Here's the link:

http://raxanpdi.com/forum/viewtopic.php?f=5&t=97

__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: More example in raxan framework

Postby noviandi_pakuan » Mon Nov 08, 2010 8:04 am

many thank's for the info, and it's work ....

this is the great framework, it's very clean and very nice to look at , congratulation for raxan team ...

It was my pleasure can join the community and use raxan as tool to improve our knowledge ...

i hope you're not bored if i asking some question in raxan framework....

always inspired us ... and thank's.

Noviandi.
noviandi_pakuan
 
Posts: 43
Joined: Mon Nov 01, 2010 2:50 am

Re: More example in raxan framework

Postby raymond » Mon Nov 08, 2010 12:49 pm

Hi Noviandi,

Many thanks for your kind words and inspirations :)

I'm delighted to have made a valuable contribution to the open source community. Over the years I've learnt a lot from others who were patient enough to guide me along. So I think it's my turn to do my best to help others reach their success.

Raxan is truly growing and will continue to grow. A lot has changed since the initial release and we do hope that these changes will continue to add value to you and your team.

i hope you're not bored if i asking some question in raxan framework....


Feel free to ask any question at any time. By asking questions we get valuable feedback on how to make to improve the framework and make it better for everyone.


Best regards,
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron