1. Go to this page and download the library: Download codecat/nin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codecat / nin example snippets
nf_begin();
class IndexController extends \Nin\Controller {
public function actionIndex() {
echo 'This is the index page!';
}
}
class UserController extends \Nin\Controller {
public function actionProfile(string $username) {
// Do something with $username
}
}
class UserController extends \Nin\Controller {
private $user;
public function __construct(int $id) {
$this->user = User::findByPk($id);
}
public function actionPosts() {
// Do something with $this->user
}
}
class User extends \Nin\Model {
public static function tablename() { return 'users'; }
}
public static function primarykey() { return 'id'; }
$user = new User();
$user->Username = 'admin';
$user->Password = 'hunter2';
$user->Age = 24;
$user->save();
// Nin will automatically set the ID of the model after inserting it
echo 'New user ID: ' . $user->ID;
$user = User::findByPk(1);
if (!$user) {
die('No user found!');
}
echo 'Hello, ' . $user->Username;
$user = User::findByAttributes([ 'Username' => 'admin' ]);
if (!$user) {
die('No user found!');
}
echo 'Hello, ' . $user->Username;
class User extends \Nin\Model {
public static function tablename() { return 'users'; }
public function relations() {
return [
'posts' => [ HAS_MANY, 'Post', 'Author' ],
];
}
}