I uploaded my project from wamp to my host.
When I open my site, site shows :
(1/1) InvalidArgumentException
View [welcome] not found.
.....
in FileViewFinder.php line 137
FileViewFinder.php:
<?php
namespace Illuminate\View;
use InvalidArgumentException;
use Illuminate\Filesystem\Filesystem;
class FileViewFinder implements ViewFinderInterface
{
/**
* The filesystem instance.
*
* #var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The array of active view paths.
*
* #var array
*/
protected $paths;
/**
* The array of views that have been located.
*
* #var array
*/
protected $views = [];
/**
* The namespace to file path hints.
*
* #var array
*/
protected $hints = [];
/**
* Register a view extension with the finder.
*
* #var array
*/
protected $extensions = ['blade.php', 'php', 'css'];
/**
* Create a new file view loader instance.
*
* #param \Illuminate\Filesystem\Filesystem $files
* #param array $paths
* #param array $extensions
* #return void
*/
public function __construct(Filesystem $files, array $paths, array $extensions = null)
{
$this->files = $files;
$this->paths = $paths;
if (isset($extensions)) {
$this->extensions = $extensions;
}
}
/**
* Get the fully qualified location of the view.
*
* #param string $name
* #return string
*/
public function find($name)
{
if (isset($this->views[$name])) {
return $this->views[$name];
}
if ($this->hasHintInformation($name = trim($name))) {
return $this->views[$name] = $this->findNamespacedView($name);
}
return $this->views[$name] = $this->findInPaths($name, $this->paths);
}
/**
* Get the path to a template with a named path.
*
* #param string $name
* #return string
*/
protected function findNamespacedView($name)
{
list($namespace, $view) = $this->parseNamespaceSegments($name);
return $this->findInPaths($view, $this->hints[$namespace]);
}
/**
* Get the segments of a template with a named path.
*
* #param string $name
* #return array
*
* #throws \InvalidArgumentException
*/
protected function parseNamespaceSegments($name)
{
$segments = explode(static::HINT_PATH_DELIMITER, $name);
if (count($segments) != 2) {
throw new InvalidArgumentException("View [$name] has an invalid name.");
}
if (! isset($this->hints[$segments[0]])) {
throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");
}
return $segments;
}
/**
* Find the given view in the list of paths.
*
* #param string $name
* #param array $paths
* #return string
*
* #throws \InvalidArgumentException
*/
protected function findInPaths($name, $paths)
{
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if ($this->files->exists($viewPath = $path.'/'.$file)) {
return $viewPath;
}
}
}
throw new InvalidArgumentException("View [$name] not found.");
}
/**
* Get an array of possible view files.
*
* #param string $name
* #return array
*/
protected function getPossibleViewFiles($name)
{
return array_map(function ($extension) use ($name) {
return str_replace('.', '/', $name).'.'.$extension;
}, $this->extensions);
}
/**
* Add a location to the finder.
*
* #param string $location
* #return void
*/
public function addLocation($location)
{
$this->paths[] = $location;
}
/**
* Prepend a location to the finder.
*
* #param string $location
* #return void
*/
public function prependLocation($location)
{
array_unshift($this->paths, $location);
}
/**
* Add a namespace hint to the finder.
*
* #param string $namespace
* #param string|array $hints
* #return void
*/
public function addNamespace($namespace, $hints)
{
$hints = (array) $hints;
if (isset($this->hints[$namespace])) {
$hints = array_merge($this->hints[$namespace], $hints);
}
$this->hints[$namespace] = $hints;
}
/**
* Prepend a namespace hint to the finder.
*
* #param string $namespace
* #param string|array $hints
* #return void
*/
public function prependNamespace($namespace, $hints)
{
$hints = (array) $hints;
if (isset($this->hints[$namespace])) {
$hints = array_merge($hints, $this->hints[$namespace]);
}
$this->hints[$namespace] = $hints;
}
/**
* Replace the namespace hints for the given namespace.
*
* #param string $namespace
* #param string|array $hints
* #return void
*/
public function replaceNamespace($namespace, $hints)
{
$this->hints[$namespace] = (array) $hints;
}
/**
* Register an extension with the view finder.
*
* #param string $extension
* #return void
*/
public function addExtension($extension)
{
if (($index = array_search($extension, $this->extensions)) !== false) {
unset($this->extensions[$index]);
}
array_unshift($this->extensions, $extension);
}
/**
* Returns whether or not the view name has any hint information.
*
* #param string $name
* #return bool
*/
public function hasHintInformation($name)
{
return strpos($name, static::HINT_PATH_DELIMITER) > 0;
}
/**
* Flush the cache of located views.
*
* #return void
*/
public function flush()
{
$this->views = [];
}
/**
* Get the filesystem instance.
*
* #return \Illuminate\Filesystem\Filesystem
*/
public function getFilesystem()
{
return $this->files;
}
/**
* Get the active view paths.
*
* #return array
*/
public function getPaths()
{
return $this->paths;
}
/**
* Get the namespace to file path hints.
*
* #return array
*/
public function getHints()
{
return $this->hints;
}
/**
* Get registered extensions.
*
* #return array
*/
public function getExtensions()
{
return $this->extensions;
}
}
I tried several times but I could not solve this problem
I also edited the APP_URL in the .env file, but did not change
How can I fix it?
Try to clear your project cache: php artisan config:cache and php artisan cache:clear maybe the cache is looking for the file in a wrong place.
You can connect your host with vagrant ssh , after that go to your project location using CL and run this command: php artisan config:cache to regenerate the configuration.
Hope that helps you!
Related
ive an Laravel Openid Script for Wargaming Openid Login. at the moment i dont use laravel. So i will convert it into an normal PHP Script for an MVC Model based CMS called ilch 2.x
For iLch i do some plugins. But im so stupid to convert it.
The Problems comes from the request parts of this script. but i cant solf the problems.
My Skills are not so good.
`
<?php
declare(strict_types=1);
namespace Azate\Laravel\WargamingAuth;
use GuzzleHttp\Client as GuzzleClient;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Http\Request;
/**
* Class WargamingAuth
*
* #package Azate\Laravel\WargamingAuth
*/
class WargamingAuth
{
/**
* Config repository.
*
* #var ConfigRepository
*/
protected $configRepository;
/**
* Illuminate request class.
*
* #var Request
*/
protected $request;
/**
* Illuminate url class.
*
* #var UrlGenerator
*/
protected $urlGenerator;
/**
* Region.
*
* #var string
*/
protected $region;
/**
* Realm
*
* #var string
*/
protected $realm;
/**
* Callback url.
*
* #var string
*/
protected $callbackUrl;
/**
* Creates new instance.
*
* #param ConfigRepository $configRepository
* #param Request $request
* #param UrlGenerator $urlGenerator
*/
public function __construct(
ConfigRepository $configRepository,
Request $request,
UrlGenerator $urlGenerator
) {
$this->configRepository = $configRepository;
$this->request = $request;
$this->urlGenerator = $urlGenerator;
$this->region = $this->configRepository->get('wargamingAuth.defaultRegion');
$this->realm = $this->configRepository->get('app.url');
$this->callbackUrl = $this->urlGenerator->route(
$this->configRepository->get('wargamingAuth.callbackRoute')
);
}
/**
* Returns the region.
*
* #return string
*/
public function getRegion(): string
{
return $this->region;
}
/**
* Set the region.
*
* #param string $region
*/
public function setRegion(string $region)
{
$this->region = $region;
}
/**
* Returns the realm.
*
* #return string
*/
public function getRealm(): string
{
return $this->realm;
}
/**
* Set the realm.
*
* #param string $realm
*/
public function setRealm(string $realm)
{
$this->realm = $realm;
}
/**
* Returns the OpenID URL.
*
* #return string
*/
public function getOpenIdUrl(): string
{
return 'https://' . $this->region . '.wargaming.net/id/openid/';
}
/**
* Returns the redirect URL.
*
* #return string
*/
public function redirectUrl(): string
{
$params = [
'openid.ax.if_available' => 'ext0,ext1',
'openid.ax.mode' => 'fetch_request',
'openid.ax.type.ext0' => 'http://axschema.openid.wargaming.net/spa/id',
'openid.ax.type.ext1' => 'http://axschema.org/namePerson/friendly',
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.mode' => 'checkid_setup',
'openid.ns' => 'http://specs.openid.net/auth/2.0',
'openid.ns.ax' => 'http://openid.net/srv/ax/1.0',
'openid.realm' => $this->realm,
'openid.return_to' => $this->callbackUrl,
];
return $this->getOpenIdUrl() . '?' . http_build_query($params, '', '&');
}
/**
* OpenID Positive Assertions.
*
* #return bool
*/
private function isPositiveAssertion(): bool
{
$hasFields = $this->request->has([
'openid_assoc_handle',
'openid_claimed_id',
'openid_identity',
'openid_mode',
'openid_ns',
'openid_op_endpoint',
'openid_response_nonce',
'openid_return_to',
'openid_sig',
'openid_signed',
]);
$isModeIdRes = $this->request->get('openid_mode') === 'id_res';
return $hasFields && $isModeIdRes;
}
/**
* OpenID Verifying the Return URL.
*
* #return bool
*/
public function verifyingReturnUrl(): bool
{
return $this->request->get('openid_return_to') === $this->request->url();
}
/**
* Get param list for OpenID validation
*
* #return array
*/
private function getOpenIdValidationParams(): array
{
$params = [];
$signedParams = explode(',', $this->request->get('openid_signed'));
foreach ($signedParams as $item) {
$params['openid.' . $item] = $this->request->get('openid_' . str_replace('.', '_', $item));
}
$params['openid.mode'] = 'check_authentication';
$params['openid.sig'] = $this->request->get('openid_sig');
return $params;
}
/**
* OpenID Verifying Signatures (Wargaming uses Direct Verification).
*
* #return bool
*
* #throws \GuzzleHttp\Exception\GuzzleException
*/
public function verifyingSignatures(): bool
{
$httpClient = new GuzzleClient;
$response = $httpClient->request('POST', $this->getOpenIdUrl(), [
'form_params' => $this->getOpenIdValidationParams(),
]);
$content = $response->getBody()->getContents();
return strpos($content, 'is_valid:true') !== false;
}
/**
* Process to verify an OpenID assertion.
*
* #return bool
*
* #throws \GuzzleHttp\Exception\GuzzleException
*/
public function verify(): bool
{
return $this->isPositiveAssertion()
&& $this->verifyingReturnUrl()
&& $this->verifyingSignatures();
}
/**
* Returns the user data.
*
* #return array
*/
public function user(): array
{
return [
'id' => $this->request->get('openid_ax_value_ext0_1'),
'nickname' => $this->request->get('openid_ax_value_ext1_1'),
];
}
}
`
I hope i can get help from you
I fail with the requests especially with has()
I am trying to implement a method of a class to append a linked list of nodes received as an argument at the end of the last element of the invoking object. My code:
<?php
interface INode {
/**
* Set the data of the node's field
*
* #param mixed $data
*/
function setData($data);
/**
* Return the content of the data of this node
*
* #return mixed
*/
function getData();
/**
* Return the reference to the next node
*
* #return object
*/
function getNext();
} // interface INode
interface ILinkedList {
/**
* Return how many nodes are into the list
*
* #return int
*/
function getCount();
/**
* Insert a new node at the tail of the list
*
* #param mixed $item
*/
function push($item);
/**
* Append the given list to this
*
* #param LinkedList $linked_list
*/
function append(LinkedList $linked_list);
/**
* Print to video the link list as string like 1->3-> ...
*/
function printAsList();
} // interface ILinkedList
/**
* Class Node
*/
class Node implements INode {
/**
* The data of the node
*
* #var mixed
*/
private $_data;
/**
* The link to the next node
*
* #var object
*/
private $_next;
/**
* The constructor initialize attributes $_data and the link to the next node
*
* #param mixed $data
* #param object $next
*/
function __construct($data, $next = NULL)
{
$this->_data = $data;
$this->_next = $next;
}
function __toString()
{
return "{$this->_data}";
}
/**
* Set the data of the node's field
*
* #param mixed $data
*/
public function setData($data)
{
$this->_data = $data;
}
/**
* Set the reference link to the next node
*
* #param object $next
*/
protected function setNext($next)
{
$this->_next = $next;
}
/**
* Return the content of the data of this node
*
* #return mixed
*/
public function getData()
{
return $this->_data;
}
/**
* Return the reference to the next node
*
* #return object
*/
public function getNext()
{
return $this->_next;
}
} // class Node
/**
* Class LinkedList
*/
class LinkedList extends Node implements ILinkedList {
/**
* The pointer of the list
*
* #var object|NULL
*/
private $_head;
/**
* Counter of the nodes into the list
*
* #var int
*/
private $_count;
/**
* Initialize classe's attributes
*/
function __construct()
{
$this->_head = NULL;
$this->_count = 0;
}
/**
* Return the contents of the list as a string
*
* #return string
*/
function __toString()
{
return $this->printAsList();
}
/**
* Return how many nodes are into the list
*
* #return int
*/
public function getCount()
{
return $this->_count;
}
/**
* Insert a new node at the tail of the list
*
* #param mixed $item
*/
public function push($item) {
if ($this->_head !== NULL) {
// Scroll the list
/** #var Node $curr */
for($curr = $this->_head; $curr->getNext() !== NULL; $curr = $curr->getNext()) {}
// Updates the pointer of the last element to the new node
$curr->setNext(new Node($item));
}
else $this->_head = new Node($item);
$this->_count ++;
}
/**
* Append the given list to this
*
* #param LinkedList $linked_list
*/
public function append(LinkedList $linked_list)
{
if($linked_list === NULL) {
return FALSE;
}
/** #var Node $curr */
for($curr = $this->_head; $curr !== NULL; $curr = $curr->getNext()) {}
while($linked_list !== NULL) {
$curr->setNext(new Node($linked_list->getData())); // <------ Error here
$linked_list = $linked_list->getNext();
}
return TRUE;
}
/**
* Print to video the link list as string like 1->3-> ...
*/
public function printAsList()
{
$items = [];
/** #var Node $curr */
for($curr = $this->_head; $curr !== NULL; $curr = $curr->getNext()) {
echo $curr->getData() .'->';
}
}
} // class LinkedList
$a = new LinkedList;
$a->push(1);
$a->push(2);
$b = new LinkedList;
$b->push(5);
$b->push(6);
$a->append($b); // <---------------- This statement is the one with problems
?>
For example from the code, I would like after concatenating the object $a should be:
1->2->5->6
The last statement generates the error that I don't know how to correct.
Thanks in advance for any suggestions.
I modified your code and it seams to get the job done. Kindly try this code
<?php
interface INode {
/**
* Set the data of the node's field
*
* #param mixed $data
*/
function setData($data);
/**
* Return the content of the data of this node
*
* #return mixed
*/
function getData();
} // interface INode
interface ILinkedList {
/**
* Return how many nodes are into the list
*
* #return int
*/
function getCount();
/**
* Insert a new node at the tail of the list
*
* #param mixed $item
*/
function push($item);
/**
* Append the given list to this
*
* #param LinkedList $linked_list
*/
function append(LinkedList $linked_list);
/**
* Print to video the link list as string like 1->3-> ...
*/
function printAsList();
} // interface ILinkedList
/**
* Class Node
*/
class Node implements INode {
/**
* The data of the node
*
* #var mixed
*/
private $_data;
/**
* The constructor initialize attributes $_data
*
* #param mixed $data
*/
function __construct($data)
{
$this->_data = $data;
}
function __toString()
{
return "{$this->_data}";
}
/**
* Set the data of the node's field
*
* #param mixed $data
*/
public function setData($data)
{
$this->_data = $data;
}
/**
* Return the content of the data of this node
*
* #return mixed
*/
public function getData()
{
return $this->_data;
}
} // class Node
/**
* Class LinkedList
*/
class LinkedList extends Node implements ILinkedList {
/**
* The list of all nodes
*
* #var array
*/
public $nodes = [];
/**
* Counter of the nodes into the list
*
* #var int
*/
private $_count;
/**
* Initialize classe's attributes
*/
function __construct()
{
$this->_count = 0;
}
/**
* Return the contents of the list as a string
*
* #return string
*/
function __toString()
{
return $this->printAsList();
}
/**
* Return how many nodes are into the list
*
* #return int
*/
public function getCount()
{
return $this->_count;
}
/**
* Insert a new node at the tail of the list
*
* #param mixed $item
*/
public function push($item) {
$this->nodes[] = new Node($item);
$this->_count ++;
}
/**
* Append the given list to this
*
* #param LinkedList $linked_list
*/
public function append(LinkedList $linked_list)
{
$this->nodes = array_merge($this->nodes, $linked_list->nodes);
}
/**
* Print to video the link list as string like 1->3-> ...
*/
public function printAsList()
{
return implode('->', $this->getNodes());
}
/**
* Return all nodes
*
* #return array
*/
public function getNodes()
{
return $this->nodes;
}
} // class LinkedList
$a = new LinkedList;
$a->push(1);
$a->push(2);
echo $a; // 1->2
$b = new LinkedList;
$b->push(5);
$b->push(6);
echo $b; // 5->6
$a->append($b);
$b->append($a);
echo $a; // 1->2->5->6
?>
I am trying to make rest api with dingo for laravel 5.3 . I have setup dingo on my project and created a api route like this for test .
$api->version('v1', function ($api) {
$api->get('hello',function (){
return "hello";
});
});
But when i run http://localhost:8000/api/hello
Then
{
message: "Call to undefined method Illuminate\Routing\Route::getUri()",
code: 1,
status_code: 500,
debug: {
line: 98,
file: "C:\xampp\htdocs\apiTest\vendor\dingo\api\src\Routing\Adapter\Laravel.php",
class: "Symfony\Component\Debug\Exception\FatalErrorException",
trace: [
"#0 {main}"
]
}
}
is shown .
i have searched and find this solution
Call to undefined method Illuminate\Routing\Route::get()
but when i used
use Illuminate\Support\Facades\Route;
then this problem shown
FatalErrorException in Laravel.php line 116:
Call to undefined method Illuminate\Support\Facades\Route::where()
This is the Laravel.php file
<?php
namespace Dingo\Api\Routing\Adapter;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Illuminate\Routing\RouteCollection;
use Dingo\Api\Contract\Routing\Adapter;
use Dingo\Api\Exception\UnknownVersionException;
class Laravel implements Adapter
{
/**
* Laravel router instance.
*
* #var \Illuminate\Routing\Router
*/
protected $router;
/**
* Array of registered routes.
*
* #var array
*/
protected $routes = [];
/**
* Old routes already defined on the router.
*
* #var \Illuminate\Routing\RouteCollection
*/
protected $oldRoutes;
/**
* Create a new laravel routing adapter instance.
*
* #param \Illuminate\Routing\Router $router
*
* #return void
*/
public function __construct(Router $router)
{
$this->router = $router;
}
/**
* Dispatch a request.
*
* #param \Illuminate\Http\Request $request
* #param string $version
*
* #return mixed
*/
public function dispatch(Request $request, $version)
{
if (! isset($this->routes[$version])) {
throw new UnknownVersionException;
}
$routes = $this->mergeExistingRoutes($this->routes[$version]);
$this->router->setRoutes($routes);
return $this->router->dispatch($request);
}
/**
* Merge the existing routes with the new routes.
*
* #param \Illuminate\Routing\RouteCollection $routes
*
* #return \Illuminate\Routing\RouteCollection
*/
protected function mergeExistingRoutes(RouteCollection $routes)
{
if (! isset($this->oldRoutes)) {
$this->oldRoutes = $this->router->getRoutes();
}
foreach ($this->oldRoutes as $route) {
$routes->add($route);
}
return $routes;
}
/**
* Get the URI, methods, and action from the route.
*
* #param mixed $route
* #param \Illuminate\Http\Request $request
*
* #return array
*/
public function getRouteProperties($route, Request $request)
{
return [$route->getUri(), $route->getMethods(), $route->getAction()];
}
/**
* Add a route to the appropriate route collection.
*
* #param array $methods
* #param array $versions
* #param string $uri
* #param mixed $action
*
* #return \Illuminate\Routing\Route
*/
public function addRoute(array $methods, array $versions, $uri, $action)
{
$this->createRouteCollections($versions);
$route = new Route($methods, $uri, $action);
$route->where($action['where']);
foreach ($versions as $version) {
$this->routes[$version]->add($route);
}
return $route;
}
/**
* Create the route collections for the versions.
*
* #param array $versions
*
* #return void
*/
protected function createRouteCollections(array $versions)
{
foreach ($versions as $version) {
if (! isset($this->routes[$version])) {
$this->routes[$version] = new RouteCollection;
}
}
}
/**
* Get all routes or only for a specific version.
*
* #param string $version
*
* #return mixed
*/
public function getRoutes($version = null)
{
if (! is_null($version)) {
return $this->routes[$version];
}
return $this->routes;
}
public function getIterableRoutes($version = null)
{
return $this->getRoutes($version);
}
/**
* Set the routes on the adapter.
*
* #param array $routes
*
* #return void
*/
public function setRoutes(array $routes)
{
$this->routes = $routes;
}
/**
* Prepare a route for serialization.
*
* #param mixed $route
*
* #return mixed
*/
public function prepareRouteForSerialization($route)
{
$route->prepareForSerialization();
return $route;
}
/**
* Gather the route middlewares.
*
* #param \Illuminate\Routing\Route $route
*
* #return array
*/
public function gatherRouteMiddlewares($route)
{
return $this->router->gatherRouteMiddlewares($route);
}
}
Has there any solution ?
Thanks
Use $route->uri()
insted of $route->getUri()
create a pull request to dingo api after updating this
Introduction
I am using:
Windows 10 Pro
XAMPP with PHP v7.0.9
Symfony v3.1.7
Doctrine v2.5.4
StofDoctrineExtensionsBundle [1] in order to manage Tree structure.
Setting up
To setup Tree structure I used documentation on Symfony.com [2] followed by documentation on GitHub [3]. Then I proceeded with tree setup - used tree entity from example [4] and used code in [5] to create a tree.
I did setup the tree structure (that represents directories and files) called FileTree. I added several custom fields to the tree: item_name, item_extension and is_file. Removed title as I have item_name...
My FileTree entity:
<?php
namespace AppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection as ArrayCollection;
/**
* #Gedmo\Tree(type="nested")
* #ORM\Table(name="file_tree")
* use repository for handy tree functions
* #ORM\Entity(repositoryClass="AppBundle\Repository\FileTreeRepository")
*/
class FileTree
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue
*/
private $id;
/**
* #ORM\Column(type="string", length=1024)
*
* #var string
*/
private $item_path;
/**
* #ORM\Column(type="string", length=240)
*
* #var string
*/
private $item_name;
/**
* #ORM\Column(type="string", length=20)
*
* #var string
*/
private $item_extension;
/**
* #ORM\Column(type="boolean")
*/
private $is_file;
/**
* #Gedmo\TreeLeft
* #ORM\Column(type="integer")
*/
private $lft;
/**
* #Gedmo\TreeLevel
* #ORM\Column(type="integer")
*/
private $lvl;
/**
* #Gedmo\TreeRight
* #ORM\Column(type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeRoot
* #ORM\ManyToOne(targetEntity="FileTree")
* #ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
*/
private $root;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="FileTree", inversedBy="children")
* #ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #ORM\OneToMany(targetEntity="FileTree", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* #ManyToOne(targetEntity="Project", inversedBy="file_tree")
* #JoinColumn(name="project_id", referencedColumnName="id")
*/
private $project;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set itemPath
*
* #param string $itemPath
*
* #return FileTree
*/
public function setItemPath($itemPath)
{
$this->item_path = $itemPath;
return $this;
}
/**
* Get itemPath
*
* #return string
*/
public function getItemPath()
{
return $this->item_path;
}
/**
* Set itemName
*
* #param string $itemName
*
* #return FileTree
*/
public function setItemName($itemName)
{
$this->item_name = $itemName;
return $this;
}
/**
* Get itemName
*
* #return string
*/
public function getItemName()
{
return $this->item_name;
}
/**
* Set isFile
*
* #param boolean $isFile
*
* #return FileTree
*/
public function setIsFile($isFile)
{
$this->is_file = $isFile;
return $this;
}
/**
* Get isFile
*
* #return boolean
*/
public function getIsFile()
{
return $this->is_file;
}
/**
* Set lft
*
* #param integer $lft
*
* #return FileTree
*/
public function setLft($lft)
{
$this->lft = $lft;
return $this;
}
/**
* Get lft
*
* #return integer
*/
public function getLft()
{
return $this->lft;
}
/**
* Set lvl
*
* #param integer $lvl
*
* #return FileTree
*/
public function setLvl($lvl)
{
$this->lvl = $lvl;
return $this;
}
/**
* Get lvl
*
* #return integer
*/
public function getLvl()
{
return $this->lvl;
}
/**
* Set rgt
*
* #param integer $rgt
*
* #return FileTree
*/
public function setRgt($rgt)
{
$this->rgt = $rgt;
return $this;
}
/**
* Get rgt
*
* #return integer
*/
public function getRgt()
{
return $this->rgt;
}
/**
* Set root
*
* #param \AppBundle\Entity\FileTree $root
*
* #return FileTree
*/
public function setRoot(\AppBundle\Entity\FileTree $root = null)
{
$this->root = $root;
return $this;
}
/**
* Get root
*
* #return \AppBundle\Entity\FileTree
*/
public function getRoot()
{
return $this->root;
}
/**
* Set parent
*
* #param \AppBundle\Entity\FileTree $parent
*
* #return FileTree
*/
public function setParent(\AppBundle\Entity\FileTree $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* Get parent
*
* #return \AppBundle\Entity\FileTree
*/
public function getParent()
{
return $this->parent;
}
/**
* Add child
*
* #param \AppBundle\Entity\FileTree $child
*
* #return FileTree
*/
public function addChild(\AppBundle\Entity\FileTree $child)
{
$this->children[] = $child;
return $this;
}
/**
* Remove child
*
* #param \AppBundle\Entity\FileTree $child
*/
public function removeChild(\AppBundle\Entity\FileTree $child)
{
$this->children->removeElement($child);
}
/**
* Get children
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Set project
*
* #param \AppBundle\Entity\Project $project
*
* #return FileTree
*/
public function setProject(\AppBundle\Entity\Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project
*
* #return \AppBundle\Entity\Project
*/
public function getProject()
{
return $this->project;
}
/**
* toString
*
* #return string
*/
public function __toString()
{
return $this->getItemName();
}
/**
* Set itemExtension
*
* #param string $itemExtension
*
* #return FileTree
*/
public function setItemExtension($itemExtension)
{
$this->item_extension = $itemExtension;
return $this;
}
/**
* Get itemExtension
*
* #return string
*/
public function getItemExtension()
{
return $this->item_extension;
}
}
Problem
I need to order files in the folders of the tree by file type - that is: by item_extension and then by item_name. At the moment Gedmo Nestedset Tree sorts by root and lft as is shown in next code block.
public function getFileTreeNodeArray($file_tree_root_id)
{
$em = $this->getEntityManager();
$query = $em
->createQueryBuilder()
->select('ft')
->from('AppBundle:FileTree', 'ft')
->where('ft.root = :root')
->setParameter('root', $file_tree_root_id)
->orderBy('ft.root, ft.lft', 'ASC')
->getQuery();
$query->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true);
$build_my_tree = $query->getArrayResult();
return $build_my_tree;
}
Sadly adding additional ->orderBy('ft.item_extension', 'ASC') did not yield any results...
Then I learned [6] that there are 2 functions that may aide me in this endeavor reorderAll and reorder. I tried both of them, but sadly items did not change their order, they remained ordered by root and lft.
My code from Upload Listener:
$repo_file_tree = $this->entityManager->getRepository('AppBundle:FileTree');
$root_node_id = $repo_file_tree->getFileTreeRootNodeIdByProjectId($selected_node_parent_id);
$root_node = $repo_file_tree->findOneBy(array('id' => $root_node_id));
$repo_file_tree->reorder($root_node, 'item_extension, item_name', 'ASC');
$this->entityManager->flush();
or
$repo_file_tree = $this->entityManager->getRepository('AppBundle:FileTree');
$repo_file_tree->reorderAll('item_extension, item_name', 'ASC');
$this->entityManager->flush();
Question
How do I get an array with FileTree items that are ordered by item_extension, item_name?
I would be happy with ether correct Doctrine query (preferably) or with explanation what is wrong with code blocks that contain functions reorder and reorderAll.
Conclusion
What am I missing?
Please advise.
Thank you for your time and knowledge.
Just updated my project to Symfony v3.2.0
Now I get error
Invalid sort options specified: field - item_extension, item_name, direction - ASC
500 Internal Server Error - InvalidArgumentException
with above mentioned code when using reorder.
I am not sure is it occurring just now (after upgrade) or it was there also with Symfony v3.1.x.
Anyhow - it is clear that reorder does take only one field by which it orders tree branch. Not multiple fields as I tried earlier.
So the answer is: not to use several ordering fields when calling reorder function.
$repo_file_tree = $this->entityManager->getRepository('AppBundle:FileTree');
$root_node_id = $repo_file_tree->getFileTreeRootNodeIdByProjectId($selected_node_parent_id);
$root_node = $repo_file_tree->findOneBy(array('id' => $root_node_id));
$repo_file_tree->reorder($root_node, 'item_extension', 'ASC');
$this->entityManager->flush();
Symfony2 REST API
Goal: Upload images, use ImageResize to re-shape them and save them to a folder. Load them up and push to Mongo GridFS and then delete saved ones in folder.
Issue: Using unlink after flushing to mongodb triggers an error as if i have used unlink before:
Warning: file_get_contents(C:/Users/Nikola/Desktop/awesome/web\pictures\1366%20768_small.jpg): failed to open stream: No such file or directory
Note that if i don't use unlink everything goess fine.
GalleryController:
public function uploadAction(Request $request) {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content- Type, Accept");
header ("Content-Type: application/json; charset=utf-8");
$response = new ResponseModel();
try {
// Did we receive any files ?
if( $request->files->count() === 0) {
throw new CustomErrorException("No files received");
}
$pathsToDelete = [];
$names = [];
$files = $request->files;
foreach ($files as $file) {
/* #var $file UploadedFile */
// Check mime type
if(!($file->getMimeType() == 'image/jpeg' || $file->getMimeType() == 'image/png')) {
throw new CustomErrorException("We are only accepting jpg and png files.");
}
//var_dump();
// Perform image operations and save them to a temp folder
// Create small image
$imageManipulator = new ImageResize($file->getRealPath());
$imageManipulator->resizeToHeight(200);
$imageManipulator->resizeToWidth(200);
$array = explode(".", $file->getClientOriginalName());
$name = $array[0];
$ext = $array[1];
$pathSmall = 'pictures'.DIRECTORY_SEPARATOR.$name.'_small.'.$ext;
$imageManipulator->save($pathSmall);
// Create medium image
$imageManipulator = new ImageResize($file->getRealPath());
$imageManipulator->resizeToHeight(600);
$imageManipulator->resizeToWidth(600);
$array = explode(".", $file->getClientOriginalName());
$name = $array[0];
$ext = $array[1];
$pathMedium = 'pictures'.DIRECTORY_SEPARATOR.$name.'_medium.'.$ext;
$imageManipulator->save($pathMedium);
// Create Large image
$imageManipulator = new ImageResize($file->getRealPath());
$imageManipulator->resizeToHeight(1024);
$imageManipulator->resizeToWidth(1024);
$array = explode(".", $file->getClientOriginalName());
$name = $array[0];
$ext = $array[1];
$pathLarge = 'pictures'.DIRECTORY_SEPARATOR.$name.'_large.'.$ext;
$imageManipulator->save($pathLarge);
// Get locator
$configDirectories = array($_SERVER['DOCUMENT_ROOT']);
$locator = new FileLocator($configDirectories);
// Create image
$img = new Image();
$img->setName($file->getClientOriginalName());
$img->setFileSmall($locator->locate($pathSmall));
$img->setFileMedium($locator->locate($pathMedium));
$img->setFileLarge($locator->locate($pathLarge));
// Save files to the database
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($img);
$dm->flush();
array_push($pathsToDelete, $locator->locate($pathSmall));
array_push($pathsToDelete, $locator->locate($pathMedium));
array_push($pathsToDelete, $locator->locate($pathLarge));
array_push($names, $file->getClientOriginalName());
}
// Delete files after persisting
foreach ($pathsToDelete as $p) {
unlink($p);
}
//Load files from db
foreach ($names as $n) {
$image = $this->get('doctrine_mongodb')->getRepository('BlueAwesomeBundle:Image')
->findOneBy(['name' => $n]);
//save them for testing
file_put_contents($n, $image->getFileSmall64());
}
$response->setData(['success' => true]);
}
catch(CustomErrorException $e) {
$response->setErr($e->getMessage());
}
return new JsonResponse($response);
}
Image
namespace Blue\AwesomeBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Date;
use Doctrine\ODM\MongoDB\Mapping\Annotations\File;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
use MongoId;
class Image
{
/**
* #var MongoId $id
*/
protected $id;
/**
* #var string $name
*/
protected $name;
/**
* #var file $file_small
*/
protected $file_small;
/**
* #var file $file_medium
*/
protected $file_medium;
/**
* #var file $file_large
*/
protected $file_large;
/**
* #var date $uploadDate
*/
protected $uploadDate;
/**
* #var string $mimeType
*/
protected $mimeType;
/**
* #var int $length
*/
protected $length;
/**
* #var int $chunkSize
*/
protected $chunkSize;
/**
* #var string $md5
*/
protected $md5;
/**
* Get id
*
* #return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string $name
*/
public function getName()
{
return $this->name;
}
/**
* Set fileSmall
*
* #param file $fileSmall
* #return self
*/
public function setFileSmall($fileSmall)
{
$this->file_small = $fileSmall;
return $this;
}
/**
* Get fileSmall
*
* #return file $fileSmall
*/
public function getFileSmall()
{
return $this->file_small;
}
/** Returns 64base representation
* #return string
*/
public function getFileSmall64() {
return $this->file_small->getBytes();
}
/**
* Set fileMedium
*
* #param file $fileMedium
* #return self
*/
public function setFileMedium($fileMedium)
{
$this->file_medium = $fileMedium;
return $this;
}
/**
* Get fileMedium
*
* #return file $fileMedium
*/
public function getFileMedium()
{
return $this->file_medium;
}
/** Returns 64base representation
* #return string
*/
public function getFileMedium64() {
return $this->file_medium->getBytes();
}
/**
* Set fileLarge
*
* #param file $fileLarge
* #return self
*/
public function setFileLarge($fileLarge)
{
$this->file_large = $fileLarge;
return $this;
}
/** Returns 64base representation
* #return string
*/
public function getFileLarge64() {
return $this->file_large->getBytes();
}
/**
* Get fileLarge
*
* #return file $fileLarge
*/
public function getFileLarge()
{
return $this->file_large;
}
/**
* Set uploadDate
*
* #param date $uploadDate
* #return self
*/
public function setUploadDate($uploadDate)
{
$this->uploadDate = $uploadDate;
return $this;
}
/**
* Get uploadDate
*
* #return date $uploadDate
*/
public function getUploadDate()
{
return $this->uploadDate;
}
/**
* Set mimeType
*
* #param string $mimeType
* #return self
*/
public function setMimeType($mimeType)
{
$this->mimeType = $mimeType;
return $this;
}
/**
* Get mimeType
*
* #return string $mimeType
*/
public function getMimeType()
{
return $this->mimeType;
}
/**
* Set length
*
* #param int $length
* #return self
*/
public function setLength($length)
{
$this->length = $length;
return $this;
}
/**
* Get length
*
* #return int $length
*/
public function getLength()
{
return $this->length;
}
/**
* Set chunkSize
*
* #param int $chunkSize
* #return self
*/
public function setChunkSize($chunkSize)
{
$this->chunkSize = $chunkSize;
return $this;
}
/**
* Get chunkSize
*
* #return int $chunkSize
*/
public function getChunkSize()
{
return $this->chunkSize;
}
/**
* Set md5
*
* #param string $md5
* #return self
*/
public function setMd5($md5)
{
$this->md5 = $md5;
return $this;
}
/**
* Get md5
*
* #return string $md5
*/
public function getMd5()
{
return $this->md5;
}
/**
* (PHP 5 >= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* #link http://php.net/manual/en/jsonserializable.jsonserialize.php
* #return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
function jsonSerialize()
{
return (object) [
'id' => $this->id,
'name' => $this->name,
'file' => $this->getFileSmall64(),
'mimeType' => $this->mimeType
];
}
}
Image.mongodb.yml
Blue\AwesomeBundle\Document\Image:
type: document
fields:
id:
id: true
name:
type: string
file_small:
type: file
file_medium:
type: file
file_large:
type: file
uploadDate:
type: date
mimeType:
type: string
length:
type: int
chunkSize:
type: string
md5:
type: string
SOLVED
The thing is that i tried to store multiple files in one image document. Well gridfs doesn't work that way, so the solution is to make an image Document that only stores 1 file. In my case i created 3 documents with different sizes with different subname field based on shared name field.