LuckyCyborg on 4.2
Update MigrationMakeCommand.php Merge pull request #27 from nic… (compare)
LuckyCyborg on 4.2
Improve the Users module (compare)
LuckyCyborg on 4.2
Small changes (compare)
LuckyCyborg on 4.2
Improve the Localization (compare)
LuckyCyborg on 4.2
Small changes (compare)
LuckyCyborg on 4.2
Improve the Localization (compare)
LuckyCyborg on 4.2
Improve the Localization (compare)
LuckyCyborg on 4.2
Small changes (compare)
<?= Asset::position('header', 'css'); ?>
. Please tell me how to correctly pass the array of parameters I need from the controller to it. I think need like this View::shares(name, arr)
but what name?
Asset::register()
Asset
facade is for the Assets Manager, found as Nova\Routing\Assets\AssetManager
which is rather smaller class and I invite you to study it, even there are not docs.
/**
* Register new Assets.
*
* @param string|array $assets
* @param string $type
* @param string $position
* @param int $order
* @param string $mode
*
* @return void
* @throws \InvalidArgumentException
*/
public function register($assets, $type, $position, $order = 0, $mode = 'default')
{
if (! in_array($type, $this->types)) {
throw new InvalidArgumentException("Invalid assets type [${type}]");
} else if (! in_array($mode, array('default', 'inline', 'view'))) {
throw new InvalidArgumentException("Invalid assets mode [${mode}]");
}
// The assets type and mode are valid.
else if (! empty($items = $this->parseAssets($assets, $order, $mode))) {
// We will merge the items for the specified type and position.
Arr::set($this->positions, $key = "${type}.${position}", array_merge(
Arr::get($this->positions, $key, array()), $items
));
}
}
$type
should be css
or js
, $position
is the (freely named) position, $order
is obviously the rendering order and with a special note for $mode
which usually should be default
to give you the classic files URLs, or inline
when you want to inject inline snippets like <style></style>
or <javascript></javascript>
view
when you inject inline the content of CSS and/or JS files located on the Views locations.
$item->rules
rules not rule.@Facultys2 I am afraid that Nova Framework has no support for Oracle DB. Most likely someone can write a Database extension for Oracle DB, but I think that's not a trivial task and I see here only two capable to do this task: @daveismyname and @LuckyCyborg who are also the maintainers.
@carvelle I do not think that Nova does something particular with the browser caching, at least for the standard pages, because the assets dispatcher does some kind of browser caching setup.
So, I think that Nova uses the Symfony's defaults. At least talking about the framework and its default app: https://github.com/nova-framework/app
With Novapress is another story, it does some complicated caching on pages and parts of pages. And I am not pretty sure that's designed for on-fly users switching.
Anyways, I believe that the Maintainers could give you a much better response, but I bet that it will be something like use a custom Middleware
like:
class SetupBrowserCaching
{
/**
* Handle an incoming request.
*
* @param \Nova\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);
// prepare the response here (to customize the browser caching) if isn't a file response.
return $response;
}
}
This Middleware most likely should be put on top of web
group, to be one of the last ones which process the response.
@daveismyname or @LuckyCyborg in the old SMVC router you had parameters:
Router::get('blog/(:any)', 'Controllers\\Blog@index');
// or you could
Router::get('blog/index/(:any)', 'Controllers\\Blog@index');
But the main part in both (the key) is
'blog/
or
'blog/index/
Those parts are stable, but the (:any) is dynamic. I cannot figure how you made sure a match took place, i.e., blog/index was a match so you had the correct route. If you you get this can you explain. because the (:any) part couldn't be a key? is that correct.
Like:
if (array_key_exists($key_to_check, self::$routes)) { /// just example
// where $key_to_check would be blog/index in this case...
How does the router get just key and discord the parameters part for a match?
@jimgwhit Hi, Jim!
The SMVCF 2.2 makes distinction between "base path" and its "path with (unnamed) parameters" counterpart.
Then, you should define both routes, like this:
Router::get('blog', 'Controllers\\Blog@index'); // Matches https://mypetshop/blog
Router::get('blog/(:any)', 'Controllers\\Blog@index'); // Matches https://mypetshop/blog/new-dogs-for-adoption
As you see, you need to define TWO routes for handling this job.
Regarding the routes checking, it is simple: it tries to find the routes with no regexes - if any is defined for the current URI , otherwise it tries to match the routes with regexes
ANY
specification for method.
// A route for matching both https://mypetshop/blog and https://mypetshop/blog/new-dogs-for-adoption
Router::get('blog/{slug?}', 'App\Controllers\Blog@index');
@LuckyCyborg @dcblogdev hope you are fine:
I am writing a small router and yes just trying to figure out if uri matches a route.
Just my "test data" here
$routes = [
'dog' => '\\Mini\\Controller\\DogController@indexAdmin@1',
'dog/index' => '\\Mini\\Controller\\DogController@indexAdmin@2',
'dog/indexadmin' => '\\Mini\\Controller\\DogController@indexAdmin@4',
'dog/edit' => '\\Mini\\Controller\\DogController@edit@2',
'dog/add' => '\\Mini\\Controller\\DogController@add@2',
'dog/delete' => '\\Mini\\Controller\\DogController@delete@2',
'admin/logout' => '\\Mini\\Controller\\AdminController@logout@2',
'cat/edit' => '\\Mini\\Controller\\DogController@index@2'
];
return $routes;
$key_to_check = self::chkUri(self::$uri[2], self::$uri[3]);
i.e. dog/index dog is self::$uri[2] etc
// chkUri just checks for safety does htmlentities, in case someone changes values...
function returns dog/index cleaned.
In router if I do
if (array_key_exists($key_to_check, self::$routes)) {
$torun = self::$routes[$key_to_check];
self::run($torun, $auth);
} else {
self::autoDispatch();
}
The router works perfect as long as the routes have 2 part keys like:
blog/index
dog/index
dog/edit
//etc
Where I show @4 above, it means a regular key like
dog/indexadmin
and 2 parameters, so uri
site.com/dog/indexadmin/c/no
All works good.
But I cannot figure out how to get a key to compare if
blog/{slug?}
or
blog/index/{slug?}
How does the router verify blog/index/Lucky is one of the routes.
Lucky can change to bob, john, etc. How do you determine the key in this case to compare?
I am wanting
blog/index/{slug?}
instead of
blog/index with the @3 in this case at the end.
I have gone over the smvc router, but I am somehow missing how it verifies the route is a good route.
I will probably stick with routes like:
'blog/index'
'dog/index'
so array would be
'dog/index' => '\\Mini\\Controller\\DogController@index@2',
'blog/index' => '\\Mini\\Controller\\DogController@edit@3',
site.com/blog/index/some_parameter
// the @3 means normal key 'blog/index' then one parameter @4 would be 2 parameters etc
Eventually I call
self::load($controller, $action, self::$last);
which is:
public static function load($controller, $action, $last = array())
{
$c = new $controller;
return $c->$action(...array_values($last));
}
@jimgwhit Cowboy, you have some very simplified examples about implementing routers with optional parameters there:
https://github.com/nova-framework/mini-router/blob/master/system/Routing/Router.php is a router with named parameters like Nova4
https://github.com/nova-framework/mini-router/blob/master/system/Routing/Router2.php is a router with unnamed parameters like SMVCF 2.2, but with optional parameters support.
Both lacks the support for groups and middlewares - for the sake of simplicity.
I suggest you to look on the code of those routers for your custom router.
@3
on your routes? The PHP language does not accepts variables starting with numbers.
@LuckyCyborg you remembered my nickname.
The @3 is used here
if (self::$auth === 'isauth') {
$uparts = explode('@', $torun);
$controller = isset($uparts[0]) ? $uparts[0] : null;
$action = isset($uparts[1]) ? $uparts[1] : null;
$thiscount = isset($uparts[2]) ? $uparts[2] : null;
$tvar = self::$uriCount - 2;
if ($tvar <> $thiscount) {
throw new \Exception('Route not allowed.');
die;
}
self::load($controller, $action, self::$last);
} else {
self::defaultController();
}
It's just the number of allowed parameters.
Route:
dog/indexadmin' => '\\Mini\\Controller\\DogController@indexAdmin@4
Allows 2 extra parameters
somesite.com/dog/indexadmin/c/n good
somesite.com/dog/indexadmin/c/n/whatever error
But thanks, I will look at the other router you mentioned.
@jimgwhit I believe that your idea to configure the number of "accepted parameters" on actions (controller methods) via routes and doing checks only on the base paths is, well... quite bad. I dare to say: terrible.
Because you can have same base path but different controllers. And no HTTP method checking is epic bad.
Then, how you solve in your way something like this?
// The Menus CRUD.
Route::paginate( 'menus', 'Menus@index');
Route::post('menus', 'Menus@store');
Route::post('menus/{id}', 'Menus@update');
Route::post('menus/{id}/destroy', 'Menus@destroy');
// The Menu Items CRUD.
Route::get( 'menus/{id}', 'MenuItems@index');
Route::post('menus/{id}/items/{itemId}', 'MenuItems@update');
Route::post('menus/{id}/items/{itemId}/destroy', 'MenuItems@destroy');
Route::post('menus/{id}/{mode}', 'MenuItems@store')->where('mode', '(posts|taxonomies|custom)');
Route::post('menus/{id}/items', 'MenuItems@order');
This is just an part of routing from Content module from Nova Press.
There, menus/{id}
on POST method goes to Menus@update
and the GET one goes to MenuItems@index
And there is menus/{id}/{mode}
and menus/{id}/items
which are basically quite similar as paths, but they points to different actions.
@end_if_twitter Hi!
I guess that by "mini" you talk about this repository: https://github.com/nova-framework/mini
First, the Mini is just an experiment for a standalone MVC framework, kinda like a much simplified Nova, with no modules, themes or packages, and lacking many other things.
Please note that it is experimental code, and you should consider it alpha quality. And yes, you can say that it is "updated" in parallel with Nova.
If there will be interest for Mini, maybe I will consolidate its code to publish a stable release, but for now there are no plans for.
Secondly, there is not support for installing Mini via composer. However, you can always clone the repository via GIT.
OMG! They will preserve the Nova Framework source code for at least 1000 years as an Open Source Treasure worth of Arctic Code Vault!
@dcblogdev @LuckyCyborg Sincere congratulations for becoming both Arctic Code Vault Contributor !
:clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:
@end_if_twitter
@LuckyCyborg thanx, i`ll try it, with eventually bugs reporting... i have experience with earlier versions, so i can report complexicity vs simplicity state
Feel free to use this Mini as you like.
However, I will ask you again to be kind to bear in mind that the Mini framework has no real relationship with Nova other than it is a playground of one of Nova's developers, me.