Welcome Guest, Not a member yet? Register   Sign In
Orm and Form components for both CI3 and CI4
#1

(This post was last modified: 06-15-2017, 09:14 PM by eddmash.)

This are a set of components i have developed to assist me in developing in php projects. you might find the useful to you.

POWERORM

The ORM Component does the following:

  • Works on both codeigniter 3 and 4 see how to integrate.
  • generates migrations that are database agonistic i.e the migrations you generate when using MySQL will run seamlessly in postgres.
  • provides lazy loading.
  • no annotations just pure php.
  • Allows to fully think of the database and its table in an object oriented manner i.e. table are represented by model and columns are represented by fields. Looking at the model you can get a glimpse of how the database looks.
  • comes with a set of command line tools that assist you in development e.g. generate dummy data based on models you have generate dummy data which uses powerormfaker component.
The Model

Create and author model which represents the author database table

PHP Code:
use Eddmash\PowerOrm\Model\Model;

class 
Author extends Model
{


 
   private function unboundFields()
 
   {
 
       return [
 
           'name'=>Model::CharField(['maxLength'=>200]),
 
           'email'=>Model::EmailField()
 
       ];
 
   }




Migrations

See integration on how to access the command line tools from the choosen framework.

In CI4 once integrated, you have access to  powerorm:pmanager from ci.php script

run
Code:
php ci.php powerorm:pmanager makemigrations // generate the database agonistic migration file

The run
Code:
php ci.php powerorm:pmanager migrate // creates the actual tables represented by the model on the database


Querying::

Code:
Author::objects->get(['pk'=>1]) // retrieves the user id primary key of 1
Author::objects->all(); // retrieves all users
Author::object->filter(['name'=>'ken']); // where name is ken
Author::objects->filter(['name__startwith'=>"p"]) // where name like p%

POWERFORM

The [/url][url=http://powerorm.readthedocs.io/en/master/form/form.html]Form Component does the following:
  • Reusable forms. see introduction
  • Build in validations.
  • Represents forms as classes and form elements as form field classes
  • provides csrf verification. which can be turned on or off depending on need.
  • supports powerorm models which will makes it very easy to create and update the database.see ModelForm you can find ModelForm example
Simple comment form
PHP Code:
use Eddmash\PowerOrm\Form\Form;
class 
CommentForm extends Form
{

 
   /**
     * @inheritDoc
     */
 
   public function fields()
 
   {
 
       $FAVORITE_COLORS_CHOICES = [
 
           'blue' => 'Blue',
 
           'green' => 'Green',
 
           'black' => 'Black',
 
       ];
 
       $FAVORITE_COLORS_CHOICES2 = [
 
           'blue' => 'Blue2',
 
           'green' => 'Green2',
 
           'black' => 'Black2',
 
       ];

 
       return [
 
           'name' => Form::CharField(),
 
           'url' => Form::UrlField(),
 
           'even_field'=>Form::IntegerField(['validators'=>['validate_even']]),
 
           'moderate' => Form::BooleanField(['required' => false]), 
 
       ];
 
   }





Simple usage in the controller :
PHP Code:
if ('post' == $this->request->getMethod()):

 
   $form = new CommentForm(['data' => $this->request->getPost()]);
 
   if ($form->isValid()):

 
   endif;
else:
 
   $form = new CommentForm();
endif;

return 
view('form', ['form' => $form]); 

Usage in the view:

To display the form all the is to echo the form object returned to the view as shown below. see rendering form
PHP Code:
form method="post" novalidate

 
   <?php echo $form?>

    <input type="submit" value="Send" name="Send">
</form> 


For any kind of usage assitance please post here

https://groups.google.com/forum/#!forum/powerorm-users


For issues please post in respective Repos::


https://github.com/eddmash/powerorm
https://github.com/eddmash/powerform
https://github.com/eddmash/powerormfaker
Reply
#2

Hi,

actually I am try to test powerorm with CI4, but I facing with issues.

would you help me with the Config\Powerorm definitions?

from your documentation, how to add service:

Add this method to the Service class at application/Config/Services.php:
/**
* @param bool $getShared
* @return \Eddmash\PowerOrm\BaseOrm
*/
public static function orm($getShared = true)
{
if ($getShared):
return self::getSharedInstance('orm');
endif;

return \Eddmash\PowerOrm\Loader::webRun(\Config\Powerorm::asArray());
}

it refers to \Config\powerorm which is missing.

thank you in advance,
Regards,
Redax
Reply




Theme © iAndrew 2016 - Forum software by © MyBB